1

我的萝卜测试工作正常,但使用spork.
我进行了调试,pry发现缺少User(类常量)会导致错误。

我该怎么做才能解决?

# working (good)
bundle exec rspec spec/acceptance/features/*

# not work (bad)
bundle exec rspec spec/acceptance/features/* --drb

这是我使用该--drb选项运行时的错误。

Failure/Error: Give a user logged in:
NameError:
wrong constant name #<Module:0x007fd40a19c680>
# spec/acceptance/steps/user_steps.rb:8:in `block (2 levels) in <module:UserSteps>'
# spec/acceptance/steps/user_steps.rb:7:in `each'

这是我的 spec_helper.rb。

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/dsl'
  require 'capybara/rspec'
  require 'capybara/rails'
  require 'turnip'
  require 'turnip/capybara'
  require 'shoulda/matchers/integrations/rspec'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  Dir.glob("spec/**/*steps.rb") { |f| load f, true }

  WebMock.disable_net_connect!(:allow_localhost => true)

  Capybara.run_server = true
  Capybara.app_host = 'http://localhost'
  Capybara.server_port = 8000
  Capybara.default_selector = :css
  Capybara.javascript_driver = :webkit

  OmniAuth.config.test_mode = true

  RSpec.configure do |config|
    # ## Mock Framework
    config.mock_with :rr
    config.infer_base_class_for_anonymous_controllers = false
    config.order = "random"

    config.include FactoryGirl::Syntax::Methods
    config.include Capybara::DSL, turnip: true
    config.include Rails.application.routes.url_helpers

    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation
      DatabaseCleaner.clean_with(:truncation)
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end

    config.before(:each, js: true) do
      headless = Headless.new
      headless.start
    end
  end
end

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

end

这是 user_steps.rb。

1.  require_relative 'helper_steps'
2. 
3.  module UserSteps
4.    include HelperSteps
5. 
6.    step 'users are registered :' do |table|
7.      table.hashes.each do |row_hash|
8.       create(:user, class_params_by_row_hash(User, row_hash))
9.    end
10.  end
11. end

rails 3.2.13
rspec-rails 2.11.0
rspec 2.11.0
turnip 1.1.0
spork 1.0.0rc3

4

1 回答 1

2

我不确定为什么会出现这个问题,但你可以阻止它发生。如果您将步骤包装在模块中,则无需将truewrap 参数传递给load. 改变:

Dir.glob("spec/**/*steps.rb") { |f| load f, true }

至:

Dir.glob("spec/**/*steps.rb") { |f| load f }

这为我防止了这个错误。

参考:http ://www.ruby-doc.org/core-2.1.2/Kernel.html#method-i-load

于 2014-05-15T07:23:10.450 回答