【问题标题】:I am trying to run the Rspec request command but when i run the command rake spec:requests it is throwing me the error我正在尝试运行 Rspec 请求命令,但是当我运行命令 rake spec:requests 时,它向我抛出了错误
【发布时间】:2014-11-11 05:39:45
【问题描述】:

错误信息 失败:

  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

宝石文件

宝石文件 组:开发,:测试做 宝石'rspec-rails','2.12.0' 宝石'水豚',:git =>'git://github.com/jnicklas/capybara.git' 宝石“发射” 宝石'database_cleaner' 宝石'自动测试咆哮','0.2.9' 宝石'自动测试','4.4.6' 宝石'自动测试-rails-pure','4.1.2' 宝石'factory_girl_rails','1.0' 宝石“咆哮” 宝石'webrat','0.7.3' 结尾 组:测试做 宝石'rspec','2.12.0' 宝石'rspec-rails','2.12.0' gem 'valid_attribute'

宝石'spork' 宝石'自动测试','4.4.6' gem 'ZenTest', :require => false, :group => :test 宝石'自动测试-rails-pure','4.1.2' 宝石'自动测试咆哮','0.2.9' 宝石'factory_girl_rails','1.0' 宝石'水豚',:git =>'git://github.com/jnicklas/capybara.git' 宝石'黄瓜导轨' 宝石“发射” 宝石“守卫” 宝石'后卫-rspec' 宝石“卫兵” gem 'simplecov', :require => false, :group => :test 宝石“公制” 宝石'metric_fu' 宝石'database_cleaner' 宝石“咆哮” 宝石'email_spec' gem 'cover_me', '>= 1.0.0.rc2'

结束

【问题讨论】:

  • 请清理您的格式并添加一个明确的问题。
  • 您有身份验证设置吗?首先尝试禁用银行控制器的身份验证要求,如果可行,则添加身份验证并将 before_action: 放入您的规范中。
  • 是的,我有身份验证设置,我试过了,但它不能再次出现同样的错误。

标签: ruby-on-rails ruby rspec capybara


【解决方案1】:
  1. 试试expect(page).to have_content()
  2. 您确定可以在当前测试页面中看到属性为name="Bank Name" 的输入吗?建议您在操作前写visit some_path去您测试的网页。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 2020-01-23
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    相关资源
    最近更新 更多