Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring integration tests into main test harness
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
1 parent
c1a42d4
commit 493574c
Showing
8 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
AllCops: | ||
Include: | ||
- Guardfile | ||
- Rakefile | ||
Exclude: | ||
- .bundle/**/* | ||
- bin/**/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |