guess In order to determine the result of a guess As a code-breaker I want the mastermind to mark the guesses with black and the pegs with white "markers". Scenario: submit guess Given the secret code is "R G Y B" When I guess "R G B Y" Then the mark should be "BBWW" Monday, May 27, 13
is (. . . .)$/) do |code| @messenger = StringIO.new @game ||= Mastermind::Game.new(messenger) game.start(code) end When(/^I guess (. . . .)$/) do |guess| @game.guess(guess) end Then(/^the mark should be (.*)$/) do |mark| @messenger.string.split("\n").should include(message) end Monday, May 27, 13
of the tasks I have to do As a user I want to be able to create new tasks Scenario: Create task Given I have signed in When I go to the task form And create a new task Then the above task should be created Monday, May 27, 13
User.create(email: "[email protected]", password: "password") visit(new_user_session_path) fill_in("Email", :with => @user.email) fill_in("Password", :with => @user.password) click_button("Sign in") end When(/^I go to the task form$/) do visit(tasks_path) end When(/^create a new task$/) do fill_in('Description', :with => 'Find the meaning of life') click_button('Create Task') end Then(/^the above (.*) should be created$/) do |model| model.humanize.constantize.count().should == 1 // Task.count().should == 1 end Then(/^I should see the text "(.*)"$/) do |text| page.should have_content(text) end Monday, May 27, 13
of the tasks I have to do As a user I want to be able to create new tasks Scenario: Create task Given the User with email "[email protected]" and password "123456" exists And I visit the login page And I fill email with "[email protected]" And I fill password with "123456" And I click the submit button And I visit the new task page And I fill name with "My Task" And I fill description with "A cool description" And I click the create button Then I should be in the task page And I should see the text "My Task" And I should see the text "A cool description" Monday, May 27, 13
Use “Then debug” (breakpoint) • Group steps in different files • Organize features in subdirectories • Use backgrounds • Invoke steps within steps Monday, May 27, 13
should describe the use case Given a person with name: ‘foo’, age: 18, gender: ‘male’, marital_status_extrange_field_name: ‘single’ When I go to the single person page I should see 1 record Given a single person When I go to the single person page I should see 1 record Monday, May 27, 13
along many features as this make you lose expressiveness. Given a person with name: ‘foo’, age: 18, gender: ‘male’, marital_status_extrange_field_name: ‘single’ When I go to the single person page I should see 1 record Given a single person When I go to the single person page I should see 1 record Monday, May 27, 13