:RSpecのをload_missing_constantは、XがYを定義するために期待(とそれはありません)
...gems/activesupport-3.2.8/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected ...app/models/links/category.rb to define Links::Category (LoadError)
ファイルをapp/models/links/Category.rb
確かにLinks::Category
を定義しません。でも、見知らぬ人には、ガードと先割れスプーン(我々がテストを実行する標準的な方法)の下で実行されているときにエラーが発生していないです。
bundle exec guard -i
は問題なく期待通りにテストスイートを実行します。
先割れスプーンは、RSpecの実行するように構成されたので、私はこれを引き起こす手動rake spec
を実行している理由について少し困惑しています。
私はautoload_paths
を見て、それがlib
とlib/**
含めしかし私たちは、私が見ることができるautoload_pathsとファンキー何もしていないされたか否かをチェックすることによって解決されるように見えた同様の問題を見てきました。
config.autoload_paths += %W(#{Rails.root}/app/srC#{config.root}/app/api #{Rails.root}/app/products)
(私たちは、当社の開発マシン上で使用テストではなく、ガードを実行するために、当社のCIサーバでbundle exec rake spec
を使用している):私たちのautoload_paths
は、この(application.rbで定義されている)のように見えます。
はcategory.rbの一番上に追加されたputs 'Hey'
をロードされますcategory.rbず、下部にputs 'Yo'
、および出力inclduesにそれをスペックを実行しているとき:
DEPRECATION WARNING: ActiveAdmin::Dashboard is deprecated and will be removed in the next version
Hey
Yo
/Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/shimms/Development/lexim/app/models/links/category.rb to define Links::Category (LoadError)
アプリ/モデル/リンク/ link.rb:
class Links::Link < ActiveRecord::Base
self.table_name = 'links_category_links'
attr_accessible :description, :name, :url, :category_id
acts_as_paranoid
belongs_to :category, :class_name => 'Links::Category'
validates_presence_of :url
validates_presence_of :name
end
アプリ/モデル/リンク/ category.rb:
class Links::Category < ActiveRecord::Base
self.table_name = 'links_categories'
attr_accessible :description, :name, :space_id
acts_as_paranoid
extend FriendlyId
friendly_id :name, :use => :scoped, :scope => :space
belongs_to :space
belongs_to_space(:space)
has_many :links, :class_name => 'Links::Link'
validates_presence_of :name
end
spec_helper.rb
require File.expand_path('../../config/environment', __FILE__)
require 'rubygems'
require 'rails/all'
require 'rspec/rails'
require 'factory_girl'
system "#{Rails.root.to_s}/db/test.db"
ENV['RAILS_ENV'] ||= 'test'
load_schema = lambda {
load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
# ActiveRecord::Migrator.up('db/migrate') # use migrations
}
silence_stream(STDOUT, &load_schema)
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.mock_with :rspec
config.fixture_path = "#{Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
ActiveSupport::Dependencies.clear
end
**エラー*が発生する最も簡単なcategory_spec.rb:
require 'spec_helper'
describe Links::Category do
pending "add some examples to (or delete) #{__FILE__}"
end
レーキ実行:
➜ lexim git:(deveop) ✗ RAILS_ENV=test be rake spec --trace
** Invoke spec (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
Agent is configured to send raw SQL to the service
Agent is configured to send raw SQL to the service
DEPRECATION WARNING: Passing :tag, :class and others to use is deprecated. Please invoke b.use :input, :wrap_with => {:class=>"span4"} instead. (called from block (2 levels) in <top (required)> at /Users/shimms/Development/lexim/config/initializers/simple_form.rb:47)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
** Execute spec
/Users/shimms/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -S rspec ./spec/product_features_spec.rb ./spec/controllers/lexim/logo_controller_spec.rb ./spec/mailers/enterprise_enquiry_mailer_spec.rb ./spec/mailers/new_account_mailer_spec.rb ./spec/mailers/user_mailer_spec.rb ./spec/models/account_boltons_spec.rb ./spec/models/account_spec.rb ./spec/models/account_status_spec.rb ./spec/models/address_spec.rb ./spec/models/admin/import_spec.rb ./spec/models/admin_user_spec.rb ./spec/models/assignment_materials_spec.rb ./spec/models/assignment_submission_rubric_selection_spec.rb ./spec/models/assignments/submission_files_spec.rb ./spec/models/assignments/submission_spec.rb ./spec/models/bolton_screenshot_spec.rb ./spec/models/bolton_spec.rb ./spec/models/bolton_status_spec.rb ./spec/models/calendar/entry_spec.rb ./spec/models/calendar/event_sharing_spec.rb ./spec/models/calendar_spec.rb ./spec/models/cancellation_reason_spec.rb ./spec/models/charge_spec.rb ./spec/models/client_application_spec.rb ./spec/models/common_cartridge/export_spec.rb ./spec/models/credit_card_spec.rb ./spec/models/discussions/reply_spec.rb ./spec/models/discussions/tag_spec.rb ./spec/models/education_domain_name_spec.rb ./spec/models/email_address_validation_spec.rb ./spec/models/gradebook/column_spec.rb ./spec/models/gradebook/value_spec.rb ./spec/models/gradebook_column_type_spec.rb ./spec/models/importer/user_spec.rb ./spec/models/invitation_spec.rb ./spec/models/invoice_spec.rb ./spec/models/links/category_spec.rb ./spec/models/links/link_spec.rb ./spec/models/mailing_list_spec.rb ./spec/models/material_item_spec.rb ./spec/models/materials/folder_spec.rb ./spec/models/materials/page_details_spec.rb ./spec/models/materials/page_spec.rb ./spec/models/materials/youtube_details_spec.rb ./spec/models/mobile_phone_country_carrier_spec.rb ./spec/models/mobile_phone_country_spec.rb ./spec/models/net_promoter_score_spec.rb ./spec/models/network_spec.rb ./spec/models/notification_channel_spec.rb ./spec/models/notification_event_spec.rb ./spec/models/notification_spec.rb ./spec/models/open_graph_object_authorization_spec.rb ./spec/models/plan_pool_spec.rb ./spec/models/plan_spec.rb ./spec/models/privacy_setting_spec.rb ./spec/models/product_bolton_spec.rb ./spec/models/product_spec.rb ./spec/models/quiz_spec.rb ./spec/models/quizzes/question_option_spec.rb ./spec/models/quizzes/question_spec.rb ./spec/models/quizzes/question_type_spec.rb ./spec/models/quizzes/submission_answer_option_spec.rb ./spec/models/quizzes/submission_answer_spec.rb ./spec/models/quizzes/submission_spec.rb ./spec/models/referrer_campaign_spec.rb ./spec/models/registration_spec.rb ./spec/models/rubric_spec.rb ./spec/models/rubrics/criterion_spec.rb ./spec/models/rubrics/descriptor_spec.rb ./spec/models/rubrics/level_spec.rb ./spec/models/sanitized_text_spec.rb ./spec/models/scheduled_mail_spec.rb ./spec/models/space_spec.rb ./spec/models/subscription_spec.rb ./spec/models/subscription_status_spec.rb ./spec/models/system_announcement_spec.rb ./spec/models/system_announcement_views_spec.rb ./spec/models/tip_spec.rb ./spec/models/tour_activity_spec.rb ./spec/models/unauthorized_access_spec.rb ./spec/models/unavailable_feature_request_spec.rb ./spec/models/user_activity_spec.rb ./spec/models/user_authentication_tokens_spec.rb ./spec/models/user_creation_type_spec.rb ./spec/models/user_notification_spec.rb ./spec/models/user_spec.rb ./spec/models/wall_post_likes_spec.rb ./spec/models/wallpost_spec.rb
Agent is configured to send raw SQL to the service
Agent is configured to send raw SQL to the service
DEPRECATION WARNING: Passing :tag, :class and others to use is deprecated. Please invoke b.use :input, :wrap_with => {:class=>"span4"} instead. (called from block (2 levels) in <top (required)> at /Users/shimms/Development/lexim/config/initializers/simple_form.rb:47)
DEPRECATION WARNING: ActiveAdmin::Dashboard is deprecated and will be removed in the next version
/Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/shimms/Development/lexim/app/models/links/category.rb to define Links::Category (LoadError)
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing'
from /Users/shimms/Development/lexim/spec/models/links/category_spec.rb:4:in `<top (required)>'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/shimms/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
/Users/shimms/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -S rspec ./spec/product_features_spec.rb ./spec/controllers/lexim/logo_controller_spec.rb ./spec/mailers/enterprise_enquiry_mailer_spec.rb ./spec/mailers/new_account_mailer_spec.rb ./spec/mailers/user_mailer_spec.rb ./spec/models/account_boltons_spec.rb ./spec/models/account_spec.rb ./spec/models/account_status_spec.rb ./spec/models/address_spec.rb ./spec/models/admin/import_spec.rb ./spec/models/admin_user_spec.rb ./spec/models/assignment_materials_spec.rb ./spec/models/assignment_submission_rubric_selection_spec.rb ./spec/models/assignments/submission_files_spec.rb ./spec/models/assignments/submission_spec.rb ./spec/models/bolton_screenshot_spec.rb ./spec/models/bolton_spec.rb ./spec/models/bolton_status_spec.rb ./spec/models/calendar/entry_spec.rb ./spec/models/calendar/event_sharing_spec.rb ./spec/models/calendar_spec.rb ./spec/models/cancellation_reason_spec.rb ./spec/models/charge_spec.rb ./spec/models/client_application_spec.rb ./spec/models/common_cartridge/export_spec.rb ./spec/models/credit_card_spec.rb ./spec/models/discussions/reply_spec.rb ./spec/models/discussions/tag_spec.rb ./spec/models/education_domain_name_spec.rb ./spec/models/email_address_validation_spec.rb ./spec/models/gradebook/column_spec.rb ./spec/models/gradebook/value_spec.rb ./spec/models/gradebook_column_type_spec.rb ./spec/models/importer/user_spec.rb ./spec/models/invitation_spec.rb ./spec/models/invoice_spec.rb ./spec/models/links/category_spec.rb ./spec/models/links/link_spec.rb ./spec/models/mailing_list_spec.rb ./spec/models/material_item_spec.rb ./spec/models/materials/folder_spec.rb ./spec/models/materials/page_details_spec.rb ./spec/models/materials/page_spec.rb ./spec/models/materials/youtube_details_spec.rb ./spec/models/mobile_phone_country_carrier_spec.rb ./spec/models/mobile_phone_country_spec.rb ./spec/models/net_promoter_score_spec.rb ./spec/models/network_spec.rb ./spec/models/notification_channel_spec.rb ./spec/models/notification_event_spec.rb ./spec/models/notification_spec.rb ./spec/models/open_graph_object_authorization_spec.rb ./spec/models/plan_pool_spec.rb ./spec/models/plan_spec.rb ./spec/models/privacy_setting_spec.rb ./spec/models/product_bolton_spec.rb ./spec/models/product_spec.rb ./spec/models/quiz_spec.rb ./spec/models/quizzes/question_option_spec.rb ./spec/models/quizzes/question_spec.rb ./spec/models/quizzes/question_type_spec.rb ./spec/models/quizzes/submission_answer_option_spec.rb ./spec/models/quizzes/submission_answer_spec.rb ./spec/models/quizzes/submission_spec.rb ./spec/models/referrer_campaign_spec.rb ./spec/models/registration_spec.rb ./spec/models/rubric_spec.rb ./spec/models/rubrics/criterion_spec.rb ./spec/models/rubrics/descriptor_spec.rb ./spec/models/rubrics/level_spec.rb ./spec/models/sanitized_text_spec.rb ./spec/models/scheduled_mail_spec.rb ./spec/models/space_spec.rb ./spec/models/subscription_spec.rb ./spec/models/subscription_status_spec.rb ./spec/models/system_announcement_spec.rb ./spec/models/system_announcement_views_spec.rb ./spec/models/tip_spec.rb ./spec/models/tour_activity_spec.rb ./spec/models/unauthorized_access_spec.rb ./spec/models/unavailable_feature_request_spec.rb ./spec/models/user_activity_spec.rb ./spec/models/user_authentication_tokens_spec.rb ./spec/models/user_creation_type_spec.rb ./spec/models/user_notification_spec.rb ./spec/models/user_spec.rb ./spec/models/wall_post_likes_spec.rb ./spec/models/wallpost_spec.rb failed
/Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/rake_task.rb:137:in `block (2 levels) in initialize'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:60:in `verbose'
/Users/shimms/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/rake_task.rb:127:in `block in initialize'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/shimms/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/shimms/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/shimms/.rvm/gems/[email protected]/bin/rake:23:in `load'
/Users/shimms/.rvm/gems/[email protected]/bin/rake:23:in `<main>'
Tasks: TOP => spec
私は非常によく似た問題を抱えているため、私をブロックしています。私の場合は、これをRSpec(またはrspec-rails)特有の問題に絞っています。さらに。それは名前空間モデルを呼び出す特定のコンテキストに制限されています。 – GrooveStomp
Links :: Categoryを定義するコードを投稿できますか? category.rbの上部に「puts 'hey'」と書いても、実際に端末に "hey"が印刷されますか?私たちは自分でそれを試すことができるように、あなたのアプリケーション全体のzipファイルを投稿できますか?そうでない場合は、問題の原因となる最小限のサンプルアプリケーションを作成できますか?あなたはそのエラーのためのunabridgedスタックトレースを提供できますか? –
Davidに感謝します。質問に感謝します。私はあなたが頼んだ(あなたが残念なことに、その閉鎖されたソースアプリケーションのアプリケーションのジップを行うことはできません)と同じくらい置くでしょう。確かに簡単なレポを作成しようとします。まもなくあなたに戻ってきてください:) –