Module: Wukong::SpecHelpers::IntegrationTests
- Included in:
- Wukong::SpecHelpers
- Defined in:
- lib/wukong/spec_helpers/integration_tests.rb
Overview
This module defines methods that are helpful to use in integration tests which require reading files from the local repository.
Integration tests will spawn new system processes with their own environments. This module provides methods and hooks for customizing that environment.
Instance Method Summary collapse
-
#bin_dir(*args) ⇒ String
The directory to add to the
PATH
environment variable for the spawned processes. -
#command(*args, options = {}) ⇒ Object
Spawn a command and capture its STDOUT, STDERR, and exit code.
-
#examples_dir(*args) ⇒ String
The directory to use for examples for the spawned process.
-
#exit_with(code) ⇒ Object
Checks that the command exits with the given
code
. -
#have_stderr(*expectations) ⇒ Object
Checks that each
expectation
appears in the STDERR of the command. -
#have_stdout(*expectations) ⇒ Object
Checks that each
expectation
appears in the STDOUT of the command. -
#integration_cwd ⇒ String
The directory to spawn new processes in.
-
#integration_env ⇒ Hash
A Hash of environment variables to use for the spawned process.
-
#lib_dir(*args) ⇒ String
The directory to add to the
RUBYLIB
environment variable for the spawned processes.
Instance Method Details
#bin_dir(*args) ⇒ String
The directory to add to the PATH
environment variable for
the spawned processes.
If args
are given, return a path within this directory.
34 35 36 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 34 def bin_dir *args root.join('bin', *args).to_s end |
#command(*args, options = {}) ⇒ Object
Spawn a command and capture its STDOUT, STDERR, and exit code.
The args
will be joined together into a command line.
It is expected that you will use the matchers defined in IntegrationMatchers in your integration tests:
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 135 def command *args a = args.flatten.compact = (a.last.is_a?(Hash) ? a.pop : {}) env = ENV.to_hash.dup env.merge!(integration_env) if respond_to?(:integration_env) env.merge!([:env] || {}) cwd = [:cwd] cwd ||= (respond_to?(:integration_cwd) ? integration_cwd : Dir.pwd) IntegrationTestRunner.new(a, cwd: cwd, env: env) end |
#examples_dir(*args) ⇒ String
The directory to use for examples for the spawned process.
If args
are given, return a path within this directory.
44 45 46 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 44 def examples_dir *args root.join('examples', *args).to_s end |
#exit_with(code) ⇒ Object
Checks that the command exits with the given code
.
92 93 94 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 92 def exit_with code ExitCodeMatcher.new(code) end |
#have_stderr(*expectations) ⇒ Object
Checks that each expectation
appears in the STDERR of the
command. Order is irrelevant and each expectation
can be
either a String to check for inclusion or a Regexp to match
with.
85 86 87 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 85 def have_stderr *expectations StderrMatcher.new(*expectations) end |
#have_stdout(*expectations) ⇒ Object
Checks that each expectation
appears in the STDOUT of the
command. Order is irrelevant and each expectation
can be
either a String to check for inclusion or a Regexp to match
with.
75 76 77 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 75 def have_stdout *expectations StdoutMatcher.new(*expectations) end |
#integration_cwd ⇒ String
The directory to spawn new processes in.
65 66 67 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 65 def integration_cwd root.to_s end |
#integration_env ⇒ Hash
A Hash of environment variables to use for the spawned process.
By default, will put the IntegrationHelper#lib_dir on the
RUBYLIB
and the IntegrationHelper#bin_dir on the PATH
.
55 56 57 58 59 60 |
# File 'lib/wukong/spec_helpers/integration_tests.rb', line 55 def integration_env { "PATH" => [bin_dir.to_s, ENV["PATH"]].compact.join(':'), "RUBYLIB" => [lib_dir.to_s, ENV["RUBYLIB"]].compact.join(':') } end |