我有以下Rakefile:
require File.expand_path('../config/application', __FILE__)
A4aa2::Application.load_tasks
if defined? RSpec
task(:default).clear
task default: :'spec:fuubar'
namespace :spec do
desc 'Run all specs in spec directory (with Fuubar formatter)'
RSpec::Core::RakeTask.new(:fuubar) do |task|
task.rspec_opts = [task.rspec_opts.to_s, '--color --format Fuubar'].compact.join ' '
end
end
end
我明确核对if defined? RSpec
,但这并不能防止以下错误:
rake db:seed RAILS_ENV=production --trace
rake aborted!
NameError: uninitialized constant RSpec::Core
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/Rakefile:13:in `block in <top (required)>'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/task_manager.rb:209:in `in_namespace'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/dsl_definition.rb:147:in `namespace'
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/Rakefile:11:in `<top (required)>'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:689:in `raw_load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:77:in `block in run'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/josh/.rvm/gems/ruby-2.1.0@a4aa2/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/josh/Documents/Work/Access4All/projects/a4aa2/src/bin/rake:4:in `<main>'
我是否还必须检查是否已定义RSpec::Core
?并且whay在生产环境中定义为RSpec
吗?
我的Gemfile
看起来像这样:
group :development, :test do
gem 'rspec'
gem 'rspec-rails' # RSpec for Rails
我不想将RSpec放入:production
组,这就是我检查RSpec
是否在Rakefile
中定义的原因},但似乎在RSpec
中定义了:production
(虽然我只在:development
和:test
组中加载它),虽然RSpec::Core
不是。
答案 0 :(得分:1)
确保Beautiful Soup
位于read = [urllib.urlopen(link).read() for link in article_links]
data = [BeautifulSoup(i).find('title').getText() for i in read]
的{{1}}群组内。
rspec在gem rspec
组之外:
:test
在Gemfile
组内使用rspec:
:test
答案 1 :(得分:0)
通过检查适当的环境,例如,您可以完全避免此问题。 unless Rails.env.production?