Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll take a stab at this. In no particular order:</p> <p><strong>Test 2 (TodosPages home page should delete a todo and redirect to index)</strong></p> <p>It looks like your Todo table is empty in your test database, so when you call Todo.last in your controller action, you get nil and then try and call delete on nil.</p> <p>I can't see anywhere in your test where you are creating at least one Todo object before the delete test.</p> <p>On a separate note, in your controller you may want to consider using the destroy instead of the delete method.</p> <p><strong>Test 1 (TodosPages home page should create a Todo)</strong></p> <p>What do you have in your model for Todo in terms of validations? Are there any required fields? I'm guessing that :todo_item is a required field, but in your rspec test you just click on the button and don't provide any input for that field so its probably failing the model validation.</p> <p>In your controller action for add, use create! instead of create, and that should give you additional error messages if it is failing model validations.</p> <p><strong>Test 3 (TodosPages home page Add Todo )</strong></p> <p>May be failing for the same reason your above test is failing, i.e. the validations failing. Fix that first and then see if this test is passing.</p> <p>Hope this helps.</p> <p>Edit: Examples of tests passing params</p> <p>My personal preference would be to separate controller tests (testing specific controller functionality) from integration type test (making sure pages are populated properly, buttons appear and are clickable etc). For the latter I like to use Cucumber. Then you could write some much easier Controller tests using Rspec, which allow you to test specific logic as well as pass params directly to the action you are testing. A test would look like </p> <pre><code>describe "add Todo" do it "increases count by 1" do expect {post: :add, todo_item: "string"}.to change(Todo, :count).by(1) end end </code></pre> <p>Alternatively if you want to continue doing your integration test in Rspec, (assuming you are using Capybara for simulating the browser), then you would need to give your todo_item text field a unique id or name, and you could do:</p> <pre><code>it "should create a Todo" do fill_in "*todo_item_unique_id" with "some text" expect { click_button "Add todo" }.to change(Todo, :count).by(1) end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload