i am trying to learn testing for rails apps. i followed the two authlogic tutorials (basic authlogic setup and password reset) and now i am trying to add some integration tests with cucumber (i know you are supposed to do the tests 1st, but i am just trying to figure out how things work). i found this app http://github.com/hectoregm/rails-templates/tree/master with a bunch of cucumber/webrat tests setup for authlogic so i started applying them to my app. the app works fine when i do everything in the web browser, but i can not figure out why it doesn''t work with the tests. when it creates a user account it should go to the show account page and flash "account registered", but instead it is creating a user in the database (good), going to my home page(bad), and the flash is "logout successful"(bad). anyone have any guidance on what might be going wrong or how to troubleshoot this? # from my feature file Scenario: Allow an anonymous user to create account Given "hector" is an anonymous user When I go to the registration form And I fill in "login" with "hector" And I fill in "email" with "hec... at example.com" And I fill in "password" with "secret" And I fill in "password confirmation" with "secret" And I press "Register" Then I should have a successful registration # the relevent steps Given /"(.*)" is an anonymous user/ do |name| # registration_steps.rb visit ''/logout'' visit ''/'' end When /^I go to (.+)$/ do |page_name| # webrat_steps.rb visit path_to(page_name) end when /the registration form/ # paths.rb new_account_path When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| # webrat_steps.rb fill_in(field, :with => value) end When /^I press "([^\"]*)"$/ do |button| # webrat_steps.rb click_button(button) end Then /^I should have a successful registration$/ do # registration_steps.rb When ''I should see "Account registered!"'' end Then /^I should see "([^\"]*)"$/ do |text| # webrat_steps.rb response.should contain(text) end # output from running "cucumber features" Feature: Registration As a anonymous user I want be able to register So that can be productive and be cool Scenario: Allow an anonymous user to create account # features/ registration.feature:13 Given "hector" is an anonymous user # features/ step_definitions/registration_steps.rb:1 When I go to the registration form # features/ step_definitions/webrat_steps.rb:10 And I fill in "login" with "hector" # features/ step_definitions/webrat_steps.rb:22 And I fill in "email" with "hec... at example.com" # features/ step_definitions/webrat_steps.rb:22 And I fill in "password" with "secret" # features/ step_definitions/webrat_steps.rb:22 And I fill in "password confirmation" with "secret" # features/ step_definitions/webrat_steps.rb:22 And I press "Register" # features/ step_definitions/webrat_steps.rb:14 Then I should have a successful registration # features/ step_definitions/registration_steps.rb:54 expected the following element''s content to include "Account registered!": home: index Authlogic Example App 1 user currently logged in Register | Log In | Forgot password Logout successful! Home Page (Spec::Expectations::ExpectationNotMetError) ./features/step_definitions/webrat_steps.rb:94:in `/^I should see "([^\"]*)"$/'' features/registration.feature:21:in `Then I should have a successful registration'' 1 scenario 1 failed step 7 passed steps
Hector Gomez
2009-Apr-11 01:08 UTC
[rspec-users] [cucumber][rails] trouble with authlogic tests
Hi: I am the author of the rails template you linked, If you are only using the features and specs from the template your problem is that my features differ in the behavior when a succesful registration is taking place. In my features it is expected a redirection to the homepage and a flash with a successful message and a message indicating the user to check his email. The email has a confirmation link so the user has to confirm before it can be logged in. While in the tutorial the user is logged in and is redirected to his account page. Hector On Apr 9, 12:33?pm, scott <scot... at gmail.com> wrote:> i am trying to learn testing for rails apps. > i followed the two authlogic tutorials (basic authlogic setup and > password reset) and now i am trying to add some integration tests with > cucumber (i know you are supposed to do the tests 1st, but i am just > trying to figure out how things work). > > i found this apphttp://github.com/hectoregm/rails-templates/tree/master > with a bunch of cucumber/webrat tests setup for authlogic so i started > applying them to my app. > > the app works fine when i do everything in the web browser, but i can > not figure out why it doesn''t work with the tests. when it creates a > user account it should go to the show account page and flash "account > registered", but instead it is creating a user in the database (good), > going to my home page(bad), and the flash is "logout > successful"(bad). > > anyone have any guidance on what might be going wrong or how to > troubleshoot this? > > # from my feature file > Scenario: Allow an anonymous user to create account > ? Given "hector" is an anonymous user > ? When I go to the registration form > ? And I fill in "login" with "hector" > ? And I fill in "email" with "hec... at example.com" > ? And I fill in "password" with "secret" > ? And I fill in "password confirmation" with "secret" > ? And I press "Register" > ? Then I should have a successful registration > > # the relevent steps > Given /"(.*)" is an anonymous user/ do |name| # registration_steps.rb > ? visit ''/logout'' > ? visit ''/'' > end > When /^I go to (.+)$/ do |page_name| # webrat_steps.rb > ? visit path_to(page_name) > end > when /the registration form/ # paths.rb > ? new_account_path > When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| # > webrat_steps.rb > ? fill_in(field, :with => value) > end > When /^I press "([^\"]*)"$/ do |button| # webrat_steps.rb > ? click_button(button) > end > Then /^I should have a successful registration$/ do # > registration_steps.rb > ? When ''I should see "Account registered!"'' > end > Then /^I should see "([^\"]*)"$/ do |text| # webrat_steps.rb > ? response.should contain(text) > end > # output from running "cucumber features" > Feature: Registration > ? As a anonymous user > ? I want be able to register > ? So that can be productive and be cool > ? Scenario: Allow an anonymous user to create account ? # features/ > registration.feature:13 > ? ? Given "hector" is an anonymous user ? ? ? ? ? ? ? ? # features/ > step_definitions/registration_steps.rb:1 > ? ? When I go to the registration form ? ? ? ? ? ? ? ? ?# features/ > step_definitions/webrat_steps.rb:10 > ? ? And I fill in "login" with "hector" ? ? ? ? ? ? ? ? # features/ > step_definitions/webrat_steps.rb:22 > ? ? And I fill in "email" with "hec... at example.com" ? ? # features/ > step_definitions/webrat_steps.rb:22 > ? ? And I fill in "password" with "secret" ? ? ? ? ? ? ?# features/ > step_definitions/webrat_steps.rb:22 > ? ? And I fill in "password confirmation" with "secret" # features/ > step_definitions/webrat_steps.rb:22 > ? ? And I press "Register" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# features/ > step_definitions/webrat_steps.rb:14 > ? ? Then I should have a successful registration ? ? ? ?# features/ > step_definitions/registration_steps.rb:54 > ? ? ? expected the following element''s content to include "Account > registered!": > ? ? ? home: index > ? ? ? Authlogic Example App > ? ? ? 1 user currently logged in > ? ? ? Register | Log In | Forgot password > ? ? ? Logout successful! > ? ? ? Home Page > ? ? ? ?(Spec::Expectations::ExpectationNotMetError) > ? ? ? ./features/step_definitions/webrat_steps.rb:94:in `/^I should > see "([^\"]*)"$/'' > ? ? ? features/registration.feature:21:in `Then I should have a > successful registration'' > 1 scenario > 1 failed step > 7 passed steps > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users