【问题标题】:"wrong constant name" Error when using Turnip with Spork将 Turnip 与 Spork 一起使用时出现“错误的常量名称”错误
【发布时间】:2013-08-31 05:50:28
【问题描述】:

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

我该怎么做才能解决?

# 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

导轨 3.2.13
rspec-rails 2.11.0
rspec 2.11.0
萝卜 1.1.0
spork 1.0.0rc3

【问题讨论】:

  • 您解决了这个问题吗?我有同样的问题
  • 我还没解决。

标签: ruby-on-rails ruby ruby-on-rails-3 rspec spork


【解决方案1】:

我不确定为什么会出现此问题,但您可以阻止它发生。如果您将步骤包装在模块中,则无需将 true 包装参数传递给 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2018-06-16
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2015-02-17
    • 2017-08-15
    相关资源
    最近更新 更多