0
votes

Error Message Failures:

  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 file

Gem file group :development, :test do gem 'rspec-rails', '2.12.0' gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git' gem 'launchy' gem 'database_cleaner' gem 'autotest-growl', '0.2.9' gem 'autotest', '4.4.6' gem 'autotest-rails-pure', '4.1.2' gem 'factory_girl_rails', '1.0' gem 'growl' gem 'webrat', '0.7.3' end group :test do gem 'rspec', '2.12.0' gem 'rspec-rails', '2.12.0' gem 'valid_attribute'

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 'guard-rspec' gem 'guard-spork' gem 'simplecov', :require => false, :group => :test gem 'metrical' gem 'metric_fu' gem 'database_cleaner' gem 'growl' gem 'email_spec' gem 'cover_me', '>= 1.0.0.rc2'

end

1
Please clean up your formatting and add an explicit question. - Jesper
do you have authentication setup? first try disabling the authentication requirement for your banks controller and if that works then add the authentication back and put a before_action: in your spec. - Kinjal Dixit
Yeah i have authentication setup i tried that but its not working again the same error. - saurabhdexter

1 Answers

0
votes
  1. Try expect(page).to have_content()
  2. Are you sure you can see a input with attribute name="Bank Name" in your current test page. Suggest that you write visit some_path to go to the webpage you test before do the operation.