Ruby 1.9.3でrspec、devise、capybaraを使用するRails 3.2アプリに取り組んでいます
カピバラを使用している場合、ロギングのテストで多くの問題が発生しています。つまり、テストで js: true メタデータを使用している場合です。
最初に、テストでは、fill_in
およびclick_button
メソッドを使用してカピバラjs: true metadata
を介してログを記録しました。password " 両方とも正しいと確信したとき ("下のテスト コードを参照")login_as(user, :scope => :user)
また、ポルターガイストの宝石をインストールして、カピバラとjavascriptドライバーで速度を上げましたが、以前と同じ結果が得られ、ワーデンを有効または無効にしました。
ここに私のテストがあります
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
しかし、今、ワーデンが機能しているので、テストにログインできますが、これは私のテスト出力です
~/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)>'
このエラーは私には説明のつかないものです...印刷行への3つの出力結果を見てください
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">
私が言ったように、私は多くの問題を抱えています...開発モードのアプリケーションは問題なく動作します。これは、テストライブラリまたは構成の問題です
ところで...これが私のgemバージョンです
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)
完全なプロジェクトはhttps://github.com/fespinoza/personal_organizer/tree/exampleにあります
おそらくライブラリのバグであり、このプロジェクトの 1 つに対するプル リクエストの可能性があります...誰かがこれで私を助けてくれることを願っています