Cucumber + Webrat doesn't submit forms?

532 views Asked by At

I'm new to Cucumber and totally lost as to why this integration test is failing. I have the following scenarios:

Scenario: User changes profile

    Given I have an account
    When I change my profile
    Then my profile should be saved

Scenario: User changes login

    Given I have an account
    When I change my login information
    Then my account should be changed

And these step definitions:

Given /^I have an account$/ do
    @user = Factory.create(:user)
    visit login_path
    fill_in "Email", :with => @user.email
    fill_in "Password", :with => 'secret'
    click_button "Sign in"
end

When /^I change my profile$/ do
    visit edit_user_profile_path(@user)
    fill_in "First name", :with => "John"
    fill_in "Last name", :with => "Doe"
    click_button "Update Profile"
end

Then /^my profile should be saved$/ do
    @user.profile.first_name.should == "John"
    @user.profile.last_name.should == "Doe"
end

When /^I change my login information$/ do
    visit edit_user_path(@user)
    fill_in "Email", :with => "[email protected]"
    click_button "Update Login Information"
end

Then /^my account should be changed$/ do
    @user.email.should == "[email protected]"
end

And I fail the "Then" condition on both scenarios with this message:

# Scenario 1
expected: "John"
got: "Test1" (using ==) (RSpec::Expectations::ExpectationNotMetError)

# Scenario 1
expected: "[email protected]"
got: "[email protected]" (using ==) (RSpec::Expectations::ExpectationNotMetError)

So, in both cases the factory information is still present after submitting the form to update the user login or profile. However, if I test this in a real browser it works perfectly. So, why is this test failing???

Thanks for the help!

1

There are 1 answers

3
Art Shayderov On BEST ANSWER

@user is just a variable which lives inside your cucumber code block. It will not be changed. What will be changed in the test is the database record. To check that it was changed indeed you have to visit some page where user name is displayed.
(Just as you do in your real life test)