Permalink
Browse files

Replace Sham Rack with WebMock

* Use WebMock to disable HTTP requests to external services in the test
  suite.
* Move `spec/spec_helper.rb` logic to its own template to improve
  readability.

WebMock has broader community support, is well-maintained, and works
with a variety of HTTP libraries.

https://github.com/bblimke/webmock
  • Loading branch information...
1 parent 606408c commit 8718a4757fcd3701339742ea0fa45026c1da8e3d @croaky croaky committed Jul 27, 2013
Showing with 28 additions and 32 deletions.
  1. +2 −28 lib/suspenders/app_builder.rb
  2. +1 −1 templates/Gemfile_clean
  3. +0 −3 templates/simplecov_init.rb
  4. +25 −0 templates/spec_helper.rb
@@ -126,30 +126,14 @@ def set_ruby_to_version_being_used
end
def enable_database_cleaner
- replace_in_file 'spec/spec_helper.rb',
- 'config.use_transactional_fixtures = true',
- 'config.use_transactional_fixtures = false'
-
copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end
def configure_rspec
remove_file '.rspec'
copy_file 'rspec', '.rspec'
- prepend_file 'spec/spec_helper.rb', simplecov_init
-
- config = <<-RUBY
- config.expect_with :rspec do |expect|
- expect.syntax = :expect
- end
-
- config.fail_fast = true
-
- RUBY
-
- inject_into_file 'spec/spec_helper.rb',
- config,
- :after => 'RSpec.configure do |config|'
+ remove_file 'spec/spec_helper.rb'
+ copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
end
def configure_background_jobs_for_rspec
@@ -185,12 +169,6 @@ def generate_rspec
generate 'rspec:install'
end
- def configure_capybara_webkit
- append_file 'spec/spec_helper.rb' do
- "\nCapybara.javascript_driver = :webkit\n"
- end
- end
-
def generate_clearance
generate 'clearance:install'
end
@@ -297,9 +275,5 @@ def override_path_for_tests
def factories_spec_rake_task
IO.read find_in_source_paths('factories_spec_rake_task.rb')
end
-
- def simplecov_init
- IO.read find_in_source_paths('simplecov_init.rb')
- end
end
end
@@ -27,7 +27,6 @@ end
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails', '>= 2.14'
- gem 'sham_rack'
end
group :test do
@@ -37,6 +36,7 @@ group :test do
gem 'shoulda-matchers'
gem 'simplecov', require: false
gem 'timecop'
+ gem 'webmock'
end
group :staging, :production do
@@ -1,3 +0,0 @@
-require 'simplecov'
-SimpleCov.start 'rails'
-
@@ -0,0 +1,25 @@
+require 'simplecov'
+SimpleCov.start 'rails'
+
+ENV['RAILS_ENV'] = 'test'
+
+require File.expand_path('../../config/environment', __FILE__)
+
+require 'rspec/rails'
+require 'webmock/rspec'
+
+Dir[Rails.root.join('spec/support/**/*.rb')].each { |file| require file }
+
+RSpec.configure do |config|
+ config.expect_with :rspec do |c|
+ c.syntax = :expect
+ end
+
+ config.fail_fast = true
+ config.infer_base_class_for_anonymous_controllers = false
+ config.order = 'random'
+ config.use_transactional_fixtures = false
+end
+
+Capybara.javascript_driver = :webkit
+WebMock.disable_net_connect!(allow_localhost: true)

0 comments on commit 8718a47

Please sign in to comment.