我正在努力为我的警卫/ rspec测试添加工作并且到目前为止失败了。
的Gemfile:
group :development, :test do
gem 'rspec-rails', '2.14.1'
gem 'guard-rspec', '4.2.4'
gem 'guard-spork', '1.5.1'
...
end
spec_helper:
require 'rubygems'
require 'spork'
Spork.prefork do
unless ENV['DRB']
require 'simplecov'
SimpleCov.start 'rails'
end
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
require 'database_cleaner'
require 'active_record/fixtures'
require 'capybara/rails'
require 'capybara/rspec'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f }
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/db/fixtures"
config.use_transactional_fixtures = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.global_fixtures = [:character_attribute_type_categories, :character_attribute_types, :fund_types,
:professions, :financial_types, :activity_types, :legal_job_types, :menus, :menu_items, :weapon_type_categories,
:injury_types, :block_types]
config.infer_base_class_for_anonymous_controllers = false
config.backtrace_clean_patterns = [
/\/lib\d*\/ruby\//,
/bin\//,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
config.include FactoryGirl::Syntax::Methods
end
require "mocha"
end
Spork.each_run do
if ENV['DRB']
require 'simplecov'
SimpleCov.start 'rails'
end
DatabaseCleaner.clean
Brothelking::Application.reload_routes!
end
Guardfile:
guard :spork, rspec_env: { 'RAILS_ENV' => 'test' }, cucumber: false, test_unit: false, rspec: true do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch(%r{^spec/factories/.+\.rb})
watch(%r{^spec/support/.+\.rb$})
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
end
guard :rspec, cmd: "bundle exec rspec --color --format documentation --drb --backtrace", all_after_pass: false, all_on_start: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
guard 'jslint-on-rails' do
watch(%r{^app/assets/javascripts/.*\.js$})
watch('config/jslint.yml')
end
现在,当我在Guardfile中运行警卫评论spork时,一切仍然有效:
13:05:05 - INFO - Guard is using TerminalTitle to send notifications.
13:05:05 - INFO - Guard::RSpec is running
13:05:05 - INFO - Running all specs
No DRb server is running. Running in local process instead ...
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
DEPRECATION: RSpec::Core::Configuration#backtrace_clean_patterns is deprecated. Use RSpec::Core::Configuration#backtrace_exclusion_patterns instead. Called from /Users/xxx/Sites/xxx/spec/spec_helper.rb:88:in `block (2 levels) in <top (required)>'.
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
ActivitiesController
guest access
GET #index redirects to the login form
GET #show redirects to the login form
GET #new redirects to the login form
POST #create redirects to the login form
...
激活spork调用它不会:
13:00:52 - WARN - Guard::RSpec DEPRECATION WARNING: The :version option is deprecated. Only RSpec ~> 2.14 is now supported.
13:00:52 - INFO - Guard is using TerminalTitle to send notifications.
13:00:52 - INFO - Starting Spork for RSpec
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
DEPRECATION: RSpec::Core::Configuration#backtrace_clean_patterns is deprecated. Use RSpec::Core::Configuration#backtrace_exclusion_patterns instead. Called from /Users/xxx/Sites/xxx/spec/spec_helper.rb:88:in `block (2 levels) in <top (required)>'.
Spork is ready and listening on 8989!
13:01:02 - INFO - Spork server for RSpec successfully started
13:01:02 - INFO - Guard::RSpec is running
13:01:02 - INFO - Running all specs
Running tests with args ["--color", "--backtrace", "--failure-exit-code", "2", "--format", "documentation", "--format", "Guard::RSpec::Formatter", "--require", "/Users/xxx/.rvm/gems/ruby-1.9.3-p484@xxx/gems/guard-rspec-4.2.4/lib/guard/rspec/formatter.rb", "spec"]...
DEPRECATION: stub is deprecated. Use double instead. Called from /Users/xxx/Sites/xxx/spec/models/activity_report_spec.rb:22:in `block (2 levels) in <top (required)>'.
DEPRECATION: mock is deprecated. Use double instead. Called from /Users/xxx/Sites/xxx/spec/models/activity_report_spec.rb:65:in `block (2 levels) in <top (required)>'.
Done.
13:04:28 - INFO - Guard::JsLintOnRails started using config: /Users/xxx/Sites/xxx/config/jslint.yml
13:04:28 - INFO - Guard is now watching at '/Users/xxx/Sites/xxx'
有谁知道为什么这不起作用?