Skip to content

Commit

Permalink
Bring integration tests into main test harness
Browse files Browse the repository at this point in the history
We have a nice integration spec harness, so let's make sure we use it
when we're working on the gem. I'm making the following changes:

* Make `bundle exec rake` run integration specs.
* Silence a warning in the OmniAuth integration spec that has nothing to
  do with Hashie.
* Make Guard run integration specs when appropriate. Now, when you run
  all tasks you will run integration specs. Also, if you modify an
  integration spec, it will run. Lastly, if you modify anything in `lib`
  the integration specs will run.
* Remove the extra Travis build that was just for integration specs.
  Since `bundle exec rake` now runs the integration specs, we run them
  on every Travis build.
  • Loading branch information
michaelherold committed Feb 3, 2017
1 parent c1a42d4 commit 493574c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
@@ -1,4 +1,7 @@
AllCops:
Include:
- Guardfile
- Rakefile
Exclude:
- .bundle/**/*
- bin/**/*
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Expand Up @@ -20,11 +20,6 @@ matrix:
- bundle exec danger
after_script:
- bundle exec codeclimate-test-reporter
- rvm: 2.3.1
install:
- for dir in spec/integration/*; do BUNDLE_GEMFILE=$dir/Gemfile bundle; done
script:
- for dir in spec/integration/*; do BUNDLE_GEMFILE=$dir/Gemfile bundle exec rspec $dir; done
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -36,7 +36,7 @@ scheme are considered to be bugs.

### Miscellanous

* Your contribution here.
* [#397](https://github.com/intridea/hashie/pull/397): Add the integration specs harness into the main test tasks - [@michaelherold](https://github.com/michaelherold).

## [3.5.1] - 2017-01-31

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -8,6 +8,7 @@ group :development do
gem 'rubocop', '0.34.2'
gem 'guard', '~> 2.6.1'
gem 'guard-rspec', '~> 4.3.1', require: false
gem 'guard-yield', '~> 0.1.0', require: false
end

group :test do
Expand Down
22 changes: 19 additions & 3 deletions Guardfile
@@ -1,5 +1,21 @@
guard 'rspec', all_on_start: false, cmd: 'bundle exec rspec' do
watch(/^spec\/.+_spec\.rb/)
watch(/^lib\/(.+)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
require_relative 'spec/support/integration_specs'

run_all = lambda do |*|
Compat::UI.info('Running all integration tests', reset: true)
run_all_integration_specs(logger: ->(msg) { Compat::UI.info(msg) })
end

guard 'rspec', all_on_start: false, cmd: 'bundle exec rspec', run_all: { cmd: 'bundle exec rspec --exclude-pattern "spec/integration/**/*_spec.rb"' } do
watch(%r{^spec(?!/integration)/.+_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end

guard :yield, run_all: run_all do
watch(%r{^lib/(.+)\.rb}) { run_all.call }
watch(%r{^spec/integration/(?<integration>.*)/.+_spec\.rb}) do |file, integration|
Compat::UI.info(%(Running "#{integration}" integration test), reset: true)
system(integration_command(integration, 'bundle --quiet'))
system(integration_command(integration, "bundle exec rspec #{file}"))
end
end
17 changes: 16 additions & 1 deletion Rakefile
Expand Up @@ -13,4 +13,19 @@ end
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)

task default: [:rubocop, :spec]
require_relative 'spec/support/integration_specs'
task :integration_specs do
status_codes = []
handler = lambda do |status_code|
status_codes << status_code unless status_code.zero?
end

run_all_integration_specs(handler: handler, logger: ->(msg) { puts msg })

if status_codes.any?
$stderr.puts "#{status_codes.size} integration test(s) failed"
exit status_codes.last
end
end

task default: [:rubocop, :spec, :integration_specs]
2 changes: 1 addition & 1 deletion spec/integration/omniauth/integration_spec.rb
Expand Up @@ -6,7 +6,7 @@
require 'omniauth'

class MyApplication < Sinatra::Base
use Rack::Session::Cookie
use Rack::Session::Cookie, secret: 'hashie integration tests'
use OmniAuth::Strategies::Developer

get '/' do
Expand Down
36 changes: 36 additions & 0 deletions spec/support/integration_specs.rb
@@ -0,0 +1,36 @@
# Generates the bundle command for running an integration test
#
# @param [String] integration the integration folder to run
# @param [String] command the command to run
# @return [String]
def integration_command(integration, command)
"#{integration_gemfile(integration)} #{command}"
end

# Generates the Gemfile for an integration
#
# @param [String] integration the integration test name
# @return [String]
def integration_gemfile(integration)
"BUNDLE_GEMFILE=#{integration_path(integration)}/Gemfile"
end

# Generates the path to the integration
#
# @param [String] integration the integration test name
# @return [String]
def integration_path(integration)
"spec/integration/#{integration}"
end

# Runs all integration specs in their own environment
def run_all_integration_specs(handler: ->(_code) {}, logger: ->(_msg) {})
Dir['spec/integration/*']
.map { |directory| directory.split('/').last }
.each do |integration|
logger.call(%(Running "#{integration}" integration spec))
system(integration_command(integration, 'bundle --quiet'))
system(integration_command(integration, "bundle exec rspec #{integration_path(integration)}"))
handler.call($CHILD_STATUS.exitstatus)
end
end

0 comments on commit 493574c

Please sign in to comment.