/ / RSpec MustBeConfiguredBeforeExampleGroups सादे प्रोजेक्ट पर - रूबी-ऑन-रेल, रूबी-ऑन-रेल्स -3, rspec2, rspec-rails

आरएसपीसी MustBeConfiguredBeforeExampleGroups सादा परियोजना पर त्रुटि - रूबी-ऑन-रेल, रूबी-ऑन-रेल -3, आरएसपीसी 2, आरएसपीसी-रेल

मैं एक रेल 3.1 परियोजना की स्थापना कर रहा हूँ और इसे ठीक से RSpec का उपयोग करना पसंद करता हूँ।

चलने के बाद rails g rspec:install और आगे चल रहा है rspecसांत्वना संदेश इस प्रकार है:

% rspec
/Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:470:in `assert_no_example_groups_defined": RSpec"s mock_framework configuration option must be configured before any example groups are defined, but you have already defined a group. (RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError)
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:168:in `mock_framework="
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:142:in `mock_with"
from /Users/ened/project/spec/controllers/../spec_helper.rb:19
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core.rb:71:in `configure"
from /Users/ened/project/spec/controllers/../spec_helper.rb:11
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require"
from /Users/ened/project/spec/controllers/submissions_controller_spec.rb:1
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency"
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `load_spec_files"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `map"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `load_spec_files"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/command_line.rb:18:in `run"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:80:in `run_in_process"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:69:in `run"
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:10:in `autorun"
from /usr/bin/rspec:19

मेरे rspec/spec_helper.rb इस तरह दिखता है:

# This file is copied to spec/ when you run "rails generate rspec:install"
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"
require "rspec/autorun"

# 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}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

# Remove this line if you"re not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you"re not using ActiveRecord, or you"d prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end

मैंने सोचा कि यह config.mock_with का उपयोग करके पहले से ही कॉन्फ़िगर है? मैं हैरान हूँ, क्या याद आ रही है?

उत्तर:

जवाब के लिए 9 № 1

मैंने बस यही मारा। यह पता चला है कि मेरे कुछ पुराने (लगभग 1 RSPec) स्पेक्स में निम्नलिखित आवश्यक कथन थे:

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

अधिकांश नए स्पेक्स में इसके लिए स्टेटमेंट की आवश्यकता होती है:

require "spec_helper"

मैं पुरानी शैली को साफ करने की जहमत नहीं उठाता। इसका मतलब यह था कि spec_helper.rb फ़ाइलनाम को दो अलग-अलग तरीकों से आवश्यकता के लिए पारित किया गया था: एक पूर्ण पथ, एक स्थानीय पथ। इसके बदले में spec_helper.rb को दो बार निष्पादित किया गया, जिससे त्रुटि उत्पन्न हुई। सभी आवश्यक बयानों को बदलकर छोटी नई शैली के मुद्दे को तय किया।


जवाब के लिए 4 № 2

मैंने अपने रेल एप्लिकेशन के लिए इस समस्या को हल किया है।

मेरी समस्या यह थी कि दो कल्पना फाइलें गायब थीं require "spec_helper" फ़ाइल के शीर्ष पर लाइन।


जवाब के लिए 2 № 3

मैं एक ही समस्या से मिला, और मेरा मूल कारण है: कल्पना / समर्थन फ़ोल्डर में कुछ कल्पना फ़ाइलें मौजूद हैं!

जैसे

spec/support/xx_spec.rb

जो इस तरह दिखता है:

require "spec_helper"
describe XX do
...

और युक्ति / spec_helper.rb फ़ाइल में हैं:

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

यह एक ऐसी स्थिति है जो "spec_helper" असीमित समय के लिए पुनरावर्ती आवश्यक थी।

तो समाधान बहुत आसान है:

कल्पना / समर्थन फ़ोल्डर से सभी xx_spec.rb फ़ाइलों को हटा दें।


उत्तर के लिए 1 № 4

का एक मुद्दा हो सकता है Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}। मैंने इसे अपने ऐप में कॉन्फिग ब्लॉक के नीचे रखा है और यह काम किया है।