错误消息 故障:
1) Banks GET /banks displays bank
Failure/Error: visit banks_path
ActionView::Template::Error:
undefined method `include?' for nil:NilClass
# ./config/initializers/assets.rb:2:in `block in <top (required)>'
# ./app/views/devise/sessions/new.html.erb:31:in `block in _app_views_devise_sessions_new_html_erb___985177529_129572070'
# ./app/views/devise/sessions/new.html.erb:23:in `_app_views_devise_sessions_new_html_erb___985177529_129572070'
# ./spec/requests/banks_spec.rb:8:in `block (3 levels) in <top (required)>'
2) Banks POST /banks creates bank
Failure/Error: fill_in "Bank Name", :with => "corporation"
NoMethodError:
undefined method `body' for nil:NilClass
# ./spec/requests/banks_spec.rb:29:in `block (3 levels) in <top (required)>'
3) Banks POST /banks Shows bank details
Failure/Error: page.should have_content("Successfully created bank.")
NameError:
undefined local variable or method `page' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x10077cd0>
# ./spec/requests/banks_spec.rb:49:in `block (3 levels) in <top (required)>'
bank_spec.rb
require 'spec_helper'
describe "Banks" do
describe "GET /banks" do
it "displays bank " do
Bank.create!(:user_id => "1", :name => "corporation", :branch=> "matikere", :account_number=> "023800101027128", :account_type=>"SB", :address=>"#xyz street, 15th cross,domlur", :city=>"bangalore", :state_id=>1, :country_id=>1)
visit banks_path
page.should have_content("Bank name.")
page.should have_content("A/c Number.")
page.should have_content("Branch name.")
# save_and_open_page
click_link("New bank")
visit new_bank_path
click_link("show")
visit bank_path
click_link("edit")
visit edit_bank_path
click_link("Destroy")
visit banks_path
end
end
describe "POST /banks" do
it "creates bank" do
fill_in "Bank Name", :with => "corporation"
fill_in "Branch Name", :with => "matikere"
fill_in "Account number", :with => "023800101027128"
fill_in "Account type", :with => "SB"
fill_in "address", :with => "#xyz street, 15th cross,domlur"
fill_in "City", :with => "bangalore"
fill_in "State", :with => 1
fill_in "country", :with => 1
click_button "create Bank"
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
page.should have_content("Successfully added bank.")
click_link "Back to List"
visit banks_path
end
end
describe "POST /banks" do
it "Shows bank details" do
# save_and_open_page
page.should have_content("Successfully created bank.")
page.should have_content("Name", with =>"corporation")
page.should have_content("Branch Name", with =>"matikere")
page.should have_content("Account type", with =>"SB")
page.should have_content("Account number", with =>"023800101027128")
page.should have_content("Address", with =>"#xyz street, 15th cross,domlur")
page.should have_content("City", with =>"bangalore")
page.should have_content("State", with =>"karnataka")
page.should have_content("Country", with =>"India")
click_link("edit")
visit edit_bank_path
click_link("Destroy")
visit banks_path
click_link("View All")
visit banks_path
end
end
end
宝石文件
宝石文件 group:开发,:test do gem'rspec-rails','2.12.0' gem'capybara',: git =&gt; '混帐://github.com/jnicklas/capybara.git' 宝石'发射' 宝石'database_cleaner' gem'autotest-growl','0.2.9' 宝石'自动测试','4.4.6' gem'autotest-rails-pure','4.1.2' 宝石'factory_girl_rails','1.0' 宝石'咆哮' 宝石'webrat','0.7.3' 结束 组:测试做 宝石'rspec','2.12.0' gem'rspec-rails','2.12.0' gem'valid_attribute'
宝石'spork' 宝石'自动测试','4.4.6' gem'ZenTest',:require =&gt; false,:group =&gt; :测试 gem'autotest-rails-pure','4.1.2' gem'autotest-growl','0.2.9' 宝石'factory_girl_rails','1.0' gem'capybara',: git =&gt; '混帐://github.com/jnicklas/capybara.git' 宝石'黄瓜 - 铁轨' 宝石'发射' 宝石'守卫' 宝石'guard-rspec' 宝石'护卫' gem'simplecov',:require =&gt; false,:group =&gt; :测试 宝石'metrical' 宝石'metric_fu' 宝石'database_cleaner' 宝石'咆哮' 宝石'email_spec' gem'cover_me','&gt; = 1.0.0.rc2'
端
答案 0 :(得分:0)
expect(page).to have_content()
name="Bank Name"
的输入。建议您在执行操作之前编写visit some_path
以转到您测试的网页。