当前位置: 首页 > 知识库问答 >
问题:

我试图运行Rspec request命令,但当我运行命令rake spec:requests时,它会向我抛出错误

陶朝明
2023-03-14

错误消息失败:

  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

gem'spork'gem'autotest','4.4.6'gem'zentest',:require=>false,:group=>:test gem'autotest-rails-pure“,'4.1.2'gem'autotest-growl','0.2.9'gem'factory_girl_rails”,'1.0'gem'capybara“,:git=>'git://github.com/jnicklas/capybara.git'gem'cucumber-rails'gem'launchy'gem'guard'gem_cleaner'gem'growl'gem'email_spec'gem'cover_me','>=1.0.0.rc2'

结束

共有1个答案

龚振濂
2023-03-14
  1. 尝试expect(page).to have_content()
  2. 您确定可以在当前测试页面中看到属性为name=“bank name”的输入吗。建议您在执行操作之前编写visit some_path以转到您测试的网页。
 类似资料:
  • 我使用eclipse IDE编写简单的程序 代码如下 当我试图从命令提示符运行这个程序时,我得到了以下错误 线程“main”java.lang.noClassDeffounder中出现异常错误:RegexTestHarness(错误名称:java_pr/RegexTestHarness)位于java.lang.classloader.defineclass1(本机方法)位于java.lang.cl

  • 下载模板错误错误:命令失败:npm install--save--save-accet react-native@latest npm err!Windows_NT 10.0.18363 npm错误!argv“C:\程序文件\nodejs\node.exe”“C:\用户\lenovo\appdata\漫游\npm\node_modules\npm\bin\npm-cli.js”“安装”“--保存”

  • 我做过很多Android开发,从来不需要很好地理解gradle。 理想情况下,我会在设置virtualenv后运行python脚本,但对于这个问题,我很乐意使用MWE。 结果: 假设我回到我在炮轰之前如何声明我的任务: 没有我得到: 之前我在哪里 我只有以下可用: 将主体替换为命令行“dir”失败

  • Pease帮帮我!,我是新来的flutter我正在导入一个项目,当我试图运行它时,它给出了异常 /simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/simplepermissionsplugin.java:9:错误:找不到符号导入Android.support.v4.app.activitycom

  • 当我尝试运行现有的角度项目时,它被编译,但像这样抛出错误消息。 “Angular Live Development Server 正在本地主机:4200 上侦听,请在 http://localhost:4200/ **” 找不到模块“@angular/core/package.json” 当我尝试构建它显示错误时 您似乎没有依赖于“@角/核”和/或“rxjs”。这是一个错误。 我正在使用的版本是

  • 问题内容: 然后,我用Firefox扩展“ Selenium IDE”保存了一个测试用例。 现在,我想使用命令行来运行此导出的html文件。 我尝试遵循这个方法,从命令行在一个特定的测试用例中启动selenium离子,)但这种方法不起作用。 请帮我。 问题答案: 您将需要Selenium RC,可以从以下网站获得: http : //seleniumhq.org/download/ Java 1.