2

I'm working on a rails 3.2 app that uses rspec, devise and capybara under ruby 1.9.3

I've having a lot of problems for test for logging when using capybara, I mean when using the js: true metada on a test.

first, in a test, logging through capybara with the fill_in and click_button methods, it works when there's not the js: true metadata, and because of that as the capybara wiki says.. I installed warden, to use the login_as(user, :scope => :user) for direct logging, because capybara said "invalid email or password" when I was sure both of them were correct ("see test code below")

and also installed the poltergeist gem, to speed things up with capybara and javascript drivers, but I got the same results that before, enabling and disabling warden.

and here is my test

require "spec_helper"

describe "Expenses" do
  context "given a logged user" do
    let!(:user) { FactoryGirl.create(:confirmed_user) }
    let!(:supermercado) { FactoryGirl.create(:category, user: user, name: 'Supermercado') }
    let!(:books)        { FactoryGirl.create(:category, user: user, name: 'Books') }

    before(:each) do
      login_as(user, :scope => :user)
    end

    context "given the user has categories defined" do
      describe "creating expenses in bulk for today and yesterday" do
        it "create every expense and redirects to index", :wip, :js do
          visit new_expense_path

          puts user.categories.inspect
          puts user.inspect
          puts books.inspect

          within("#expenses_0_0") do
            fill_in "expenses_0_0_name", with: "supermercado 1"
            fill_in "expenses_0_0_amount", with: "6000"
            select "Supermercado", from: "expenses_0_0_category_id"
            fill_in "expenses_0_0_description", with: "cosas para la once"
          end
          click_button "Create Expenses"

          page.should have_content("Expenses were successfully created")
          current_path.should == expenses_path
        end
      end
    end
  end
end

but now, with warden working, I can log in in my test but this is my test output

~/code/personal_organizer(master…)% rspec -t wip .                                                                                                            (ruby-1.9.3-p0@perorg)
Run options: include {:wip=>true}
[]
#<User id: 98, name: "foobar", email: "foobar1@example.com", encrypted_password: "$2a$04$L0ztIG4Lvn0Z1oqTOsGizOlH4soABWN7x0CY6TwNyA1o...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-02-27 01:11:20", last_sign_in_at: "2012-02-27 01:11:20", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2012-02-27 01:11:17", confirmation_sent_at: "2012-02-27 01:11:16", unconfirmed_email: nil, created_at: "2012-02-27 01:11:16", updated_at: "2012-02-27 01:11:20">
#<Category id: 209, name: "Books", color: "#fff", ctype: "expense", user_id: 98, created_at: "2012-02-27 01:11:18", updated_at: "2012-02-27 01:11:18">
F

Failures:

  1) Expenses given a logged user given the user has categories defined creating expenses in bulk for today and yesterday create every expense and redirects to index
     Failure/Error: select "Supermercado", from: "expenses_0_0_category_id"
     Capybara::ElementNotFound:
       cannot select option, no option with text 'Supermercado' in select box 'expenses_0_0_category_id'
     # (eval):2:in `select'
     # ./spec/requests/expenses_spec.rb:41:in `block (6 levels) in <top (required)>'
     # ./spec/requests/expenses_spec.rb:38:in `block (5 levels) in <top (required)>'

this error is kind of inexplicable to me...just watch the three output results to the print lines

puts user.categories.inspect
# []
puts user.inspect
# #<User id: 98, name: "foobar", email: "foobar1@example.com", encrypted_password: "$2a$04$L0ztIG4Lvn0Z1oqTOsGizOlH4soABWN7x0CY6TwNyA1o...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-02-27 01:11:20", last_sign_in_at: "2012-02-27 01:11:20", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2012-02-27 01:11:17", confirmation_sent_at: "2012-02-27 01:11:16", unconfirmed_email: nil, created_at: "2012-02-27 01:11:16", updated_at: "2012-02-27 01:11:20">
puts books.inspect
#<Category id: 209, name: "Books", color: "#fff", ctype: "expense", user_id: 98, created_at: "2012-02-27 01:11:18", updated_at: "2012-02-27 01:11:18">

I'm having a lot of trouble as i said...and the application in development mode work just fine, it's a problem with my test libraries or configuration

by the way... here are my gem versions

Using nokogiri (1.5.0) 
Using ffi (1.0.11) 
Using childprocess (0.3.1) 
Using json_pure (1.6.5) 
Using rubyzip (0.9.6.1) 
Using selenium-webdriver (2.13.0) 
Using xpath (0.1.4) 
Using capybara (1.1.2) 
Using warden (1.1.1) 
Using devise (2.0.4) 
Using factory_girl (2.6.0) 
Using factory_girl_rails (1.7.0) 
Using haml (3.1.4) 
Using haml-rails (0.3.4) 
Using launchy (2.0.5) 
Using poltergeist (0.4.0) 
Using pry (0.9.8.2) 
Using yard (0.7.5) 
Using pry-doc (0.4.1) 
Using rails (3.2.1) 
Using rspec-core (2.8.0) 
Using rspec-expectations (2.8.0) 
Using rspec-mocks (2.8.0) 
Using rspec (2.8.0) 
Using rspec-rails (2.8.1) 

and the full project can be found in https://github.com/fespinoza/personal_organizer/tree/example

maybe is a bug in a library and a possible pull request for one of this projects...I hope someone can help me with this

fespinozacast
  • 2,484
  • 4
  • 23
  • 38

0 Answers0