Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would change this in two ways. First, the web steps have been deprecated in newer versions of Cucumber. Therefor steps like "When I fill in "blah" with "blah"" are now discouraged. Second, testing the number of users in the database isn't describing the full picture. You want to know that the user is the one you created, meaning the same name and whatever other properties you end up adding. To handle these types of steps, I find myself writing scenarios like:</p> <pre><code>Scenario: Creating a user When I create the following users: | name | | Chandler Bing | | Some Other Guy | Then I should have the following users: | name | | Chandler Bing | | Some Other Guy | </code></pre> <p>Then in your step definitions, you would do what the web steps were doing:</p> <pre><code>Given /^I create the following users:$/ do |table| table.hashes.each do |row| visit new_user_path fill_in 'Name', with: row['name'] click_button 'Create User' end end Then /^I should have the following users:$/ do |table| # Ensure users with same name are taken into account table.hashes.size.should == User.count table.hashes.each do |row| user = User.find_by_name(row['name']) user.should_not be_nil end end </code></pre> <p>A few notes about this approach:</p> <ol> <li>It allows your steps to be reusable. If you want to test the negative path and try adding an invalid user you wouldn't have to write a new step. </li> <li>Less boilerplate code in the feature file. If you have a stakeholder, it should be easier for them to read the steps.</li> <li>You will actually be learning capybara, which I know I personally took for granted with the web steps.</li> <li>You can add a bunch of users with much less code.</li> </ol>
 

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