0

最初我用 Cucumber 和 Capybara 编写了我的测试,并且效果很好。

然后我改用 Rpsec 和 Capybara,效果也很好。

然后我在尝试使资产管道正常工作时删除了我的 gemlock 文件,突然我的测试中的 URL 帮助程序停止工作。

示例错误:

 Failure/Error: visit report_areas_path(@report)
 NoMethodError:
   undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f978c64e058>
 # ./spec/features/area_spec.rb:12:in `block (3 levels) in <top (required)>'

我想让 URL 帮助程序再次工作,以便我的测试可以指导我完成资产管道的实施。我怎样才能解决这个问题?

我所有的测试都在 /spec/features 中。

相关软件如下...

/spec/spec_helper.rb:

require 'rubygems'
require 'spork'

Spork.prefork do
end

Spork.each_run do
  # This code will be run each time you run your specs.    
end    

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

require 'capybara/rspec'
require 'capybara/rails' 
require 'capybara/dsl' 
require 'capybara-screenshot/rspec'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :rspec
  config.fail_fast = true
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.before(:each) { ActionMailer::Base.deliveries.clear }
  config.use_instantiated_fixtures = false 
  config.include(Capybara, :type => :integration) 
end

宝石文件:

source 'http://rubygems.org'

gem 'rails'
gem 'activesupport'
gem 'actionmailer'
gem 'mail'
gem 'railties'
gem 'compass'
gem 'pg'
gem 'sass'
gem 'haml'
gem 'haml-rails'
gem 'susy'
gem 'jquery-rails'
gem 'google-analytics-rails'
gem 'declarative_authorization'
gem 'authlogic', '3.1.0'
gem 'simple_form'
gem 'country-select'
gem 'rails3-generators'
gem 'hirb'
gem 'debugger'
gem 'redis'
gem 'RedCloth'
gem 'friendly_id'
gem 'high_voltage'
gem 'validatious'
gem 'houdini'
gem 'growl-rspec'
gem 'interactive_rspec'
gem "rspec-rerun"

group :development do
  gem 'taps'
  gem "better_errors"
  gem "binding_of_caller"
end

group :test do
  gem 'capybara'
  gem 'rspec-rails', '2.11'
  gem 'database_cleaner', '0.6.7'
  gem 'launchy'
  gem 'spork', '~> 1.0rc'
  gem 'growl'
  gem 'capybara-screenshot'
end

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'compass-rails'
  gem 'compass-susy-plugin'
  gem 'fancy-buttons'
  gem 'jquery-ui-rails'
  gem 'uglifier'
end

/spec/features/area_spec.rb:

require 'spec_helper'

describe Area do

  before(:each) do
    @report = Report.create(:name => "The Testivate Retail Site Search Benchmark", :short_name => "Search")
  end

  describe "Guest" do

    it 'cannot list' do
      visit report_areas_path(@report)
      page.current_path.should == root_path
    end

  end

  describe "Customer" do

    it 'cannot list' do
      @user = User.create(:username => 'Virginia', :password => 'password', :password_confirmation => 'password', :email => 'example@example.com')
      @role = Role.create(:name => "customer")
      @assignment = Assignment.create(:user_id => @user.id, :role_id => @role.id)
      visit login_path
      fill_in 'Username', :with => @user.username
      fill_in 'Password', :with => @user.password
      click_on 'Login'
      visit report_areas_path(@report)
      page.current_path.should == root_path
    end

  end

  describe "Admin" do

    before(:each) do
      @user = User.create(username: 'Virginia', password: 'pass', password_confirmation: 'pass', email: 'example@example.com')
      @role = Role.create(:name => "admin")    
      @assignment = Assignment.create(user_id: @user.id, role_id: @role.id)
      visit login_path
      fill_in 'Username', :with => @user.username
      fill_in 'Password', :with => @user.password
      click_on 'Login'
      visit report_path(@report)
      click_on "New Area"
      fill_in 'Name', :with => "Search box"
      click_on 'Create Area'
    end

    it 'can create' do
      page.current_path.should == report_area_path(@report, Area.last)
      page.should have_content("Search box")
      page.should have_content("The Testivate Retail Site Search Benchmark")
    end

    it 'can list' do
      click_link 'List Areas'
      page.current_path.should == report_areas_path(@report)
      page.should have_content("Search box")
      page.should have_content("The Testivate Retail Site Search Benchmark")
    end

    it 'can area' do
      click_link 'Edit Area'
      fill_in 'Name', :with => "Search fox"
      click_on 'Update Area'
      page.current_path.should == report_area_path(@report, Area.last)
      page.should have_content("Search fox")
      page.should_not have_content("Search box")
      page.should have_content("The Testivate Retail Site Search Benchmark")
    end

    it 'can delete' do
      click_link 'Delete Area'
      page.current_path.should == report_areas_path(@report)
      page.should_not have_content("Search box")
      page.should have_content("The Testivate Retail Site Search Benchmark")
    end

    describe "must pass validations" do

      before(:each) do
        click_link 'Edit Area'
      end

      it "must have a name" do
        fill_in 'Name', :with => ""
        click_on 'Update Area'
        page.should have_content("Please enter a name for this area.")
      end

    end

  end

end
4

1 回答 1

1

解决方案是升级到最新的 rspec-rails

于 2012-12-13T05:17:34.213 回答