Friday 15 January 2010

ruby on rails - Failing person creation spec -



ruby on rails - Failing person creation spec -

i have written integration test create new person in rails app. registration form (using devise) works fine in development , in production, wanted have spec too.

however spec failing, , i'm seeing unusual behavior. spec 1 failing me - others pass.

i notice in log in dev/prod log shows

processing devise::registrationscontroller#create

and parameters passed

parameters: {"utf8"=>"✓", "authenticity_token"=>"srverzob/swegge/hnrp3j4zj7i9rk5yvy0shymgw7m=", "person"=>{"first_name"=>"warbling", "last_name"=>"goose", "email"=>"goose@test.co", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"sign up!"}

on other hand when spec run test log shows

processing devise::registrationscontroller#new html

and parameters passed

parameters: {"person"=>{"first_name"=>"warbling", "last_name"=>"goose", "email"=>"goose@test.co", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"sign up!"}

interestingly, don't see authenticity_token beingness passed in test log?

here's gemfile:

source 'https://rubygems.org' grouping :development, :test gem 'factory_girl_rails', '4.5.0' gem 'shoulda-matchers', require: false gem 'rspec-rails', '2.99.0' gem 'capybara', '2.4.4' gem 'launchy' gem 'pry' gem 'faker' gem 'populator' end grouping :test gem 'database_cleaner' gem 'email_spec' gem 'pry-byebug' end grouping :development gem 'guard-rspec', require: false gem 'spring', '1.1.3' gem 'rails_layout' end grouping :doc gem 'sdoc', '~> 0.4.0' end gem 'rails', '4.1.6' gem 'slim-rails' gem 'pg' gem 'sass-rails', '~> 4.0.3' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '2.2.4' gem 'bootstrap-sass' gem 'figaro', '1.0.0' gem 'simple_form', '~> 3.1.0.rc2' gem 'devise', '3.4.1' gem 'font-awesome-rails'

here's spec_helper.rb:

env["rails_env"] ||= 'test' require file.expand_path("../../config/environment", __file__) require 'rspec/rails' require 'shoulda/matchers' require 'faker' require 'email_spec' dir[rails.root.join("spec/support/**/*.rb")].each { |f| require f } activerecord::migration.maintain_test_schema! rspec.configure |config| config.include devise::testhelpers, :type => :controller # include mill girl syntax simplify calls factories config.include factorygirl::syntax::methods config.include emailspec::helpers config.include emailspec::matchers config.fixture_path = "#{::rails.root}/spec/fixtures" config.use_transactional_fixtures = false config.infer_base_class_for_anonymous_controllers = false config.order = "random" config.infer_spec_type_from_file_location! config.before(:suite) databasecleaner.clean_with(:truncation) end config.before(:each) databasecleaner.strategy = :transaction end config.before(:each, :js => true) databasecleaner.strategy = :truncation end config.before(:each) databasecleaner.start end config.after(:each) databasecleaner.clean end config.before(:suite) require "#{rails.root}/db/seeds.rb" end end

the spec itself:

require 'spec_helper' require 'capybara/rspec' feature 'person creates account' scenario 'successfully' visit root_path click_link 'sign up' fill_in_with_valid_data expect { click_button 'sign up!' }.to change(person, :count).by(1) email = open_email('goose@test.co') click_first_link_in_email expect(page).to have_content( "your email has been confirmed.") end def fill_in_with_valid_data(attributes = {}) fill_in 'person_first_name', :with => 'warbling' fill_in 'person_last_name', :with => 'goose' fill_in 'person_email', :with => 'goose@test.co' fill_in 'person_password', :with => 'password' fill_in 'person_password_confirmation', :with => 'password' end end

the log output of spec:

started "/people/sign_in" 127.0.0.1 @ 2014-10-31 14:31:35 -0400 processing devise::sessionscontroller#new html rendered devise/sessions/new.html.slim within layouts/application (31.2ms) completed 200 ok in 105ms (views: 87.7ms | activerecord: 2.1ms) started "/people/sign_up" 127.0.0.1 @ 2014-10-31 14:31:35 -0400 processing devise::registrationscontroller#new html rendered devise/registrations/new.html.slim within layouts/application (8.8ms) completed 200 ok in 12ms (views: 11.3ms | activerecord: 0.0ms) (0.7ms) select count(*) "people" started "/people/sign_up?person[first_name]=warbling&person[last_name]=goose&person[email]=goose%40test.co&person[password]=[filtered]&person[password_confirmation]=[filtered]&commit=sign+up%21" 127.0.0.1 @ 2014-10-31 14:31:35 -0400 processing devise::registrationscontroller#new html parameters: {"person"=>{"first_name"=>"warbling", "last_name"=>"goose", "email"=>"goose@test.co", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"sign up!"} rendered devise/registrations/new.html.slim within layouts/application (1.7ms) completed 200 ok in 4ms (views: 3.3ms | activerecord: 0.0ms) (0.3ms) select count(*) "people" (0.1ms) rollback

and in case it's helpful, registration form:

= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) |f| .container = devise_error_messages! #signupbox.mainbox.col-md-6.col-md-offset-3.col-sm-8.col-sm-offset-2 style=("margin-top:50px") .panel.panel-info .panel-heading .panel-title sign div style=("float:right; font-size: 80%; position: relative; top:-17px") = link_to "sign in", new_person_session_path .panel-body style="padding-top:30px" form#signupform.form-horizontal role="form" .input-group style=("margin-bottom: 25px") span.input-group-addon i.fa.fa-user.fa-fw = f.input_field :first_name, placeholder: 'first name', :autofocus => true, class: 'login-username form-control' .input-group style=("margin-bottom: 25px") span.input-group-addon i.fa.fa-user.fa-fw = f.input_field :last_name, placeholder: 'last name', class: 'login-username form-control' .input-group style=("margin-bottom: 25px") span.input-group-addon i.fa.fa-paper-plane.fa-fw = f.input_field :email, placeholder: 'email address', class: 'login-email form-control' .input-group style=("margin-bottom: 25px") span.input-group-addon i.fa.fa-key.fa-fw = f.input_field :password, placeholder: 'password', class: 'login-password form-control' .input-group style=("margin-bottom: 25px") span.input-group-addon i.fa.fa-key.fa-fw = f.input_field :password_confirmation, autocomplete: 'off', placeholder: 'confirm password', class: 'login-password-confirmation form-control' .form-group style="margin-top:10px" /! button .col-sm-12.controls = f.submit 'sign up!', :class => 'btn-login btn btn-success'

and output of rspec test:

rspec spec/features/person_signup_spec.rb person creates business relationship (failed - 1) failures: 1) person creates business relationship failure/error: expect { click_button 'sign up!' }.to change(person, :count).by(1) count should have been changed 1, changed 0 # ./spec/features/person_signup_spec.rb:13:in `block (2 levels) in <top (required)>' finished in 0.22247 seconds 1 example, 1 failure failed examples: rspec ./spec/features/person_signup_spec.rb:9 # person creates business relationship

it looks though have form within of form.

= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) |f| ... form#signupform.form-horizontal role="form" ...

your spec using default action 2nd embedded form. since there no action attribute specified on sec embedded form, defaults current page on /people/sign_upand since there no method attribute on sec form defaults get request when form submitted.

this why seeing form beingness submitted request same sign page.

ruby-on-rails rspec devise capybara

No comments:

Post a Comment