Extract cucumber env and steps to ease code reuse
producer extensions like producer-rails must not reimplement all the testing infrastructure, this extraction allows to setup everything with just one require call in cucumber env: require 'producer/core/testing/cucumber'
This commit is contained in:
parent
d481398980
commit
9a8ab69c8c
@ -1,51 +1 @@
|
|||||||
require 'aruba/cucumber'
|
require 'producer/core/testing/cucumber'
|
||||||
require 'aruba/in_process'
|
|
||||||
require 'producer/core'
|
|
||||||
|
|
||||||
class ArubaProgramWrapper
|
|
||||||
def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr,
|
|
||||||
kernel = Kernel)
|
|
||||||
@argv = argv
|
|
||||||
@stdin = stdin
|
|
||||||
@stdout = stdout
|
|
||||||
@stderr = stderr
|
|
||||||
@kernel = kernel
|
|
||||||
end
|
|
||||||
|
|
||||||
def execute!
|
|
||||||
Producer::Core::CLI.run!(
|
|
||||||
@argv.dup, stdin: @stdin, stdout: @stdout, stderr: @stderr
|
|
||||||
)
|
|
||||||
rescue SystemExit => e
|
|
||||||
@kernel.exit e.status
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# Raise aruba default timeout so test suite can run on a slow machine.
|
|
||||||
Before do
|
|
||||||
@aruba_timeout_seconds = 8
|
|
||||||
end
|
|
||||||
|
|
||||||
# Use aruba "in process" optimization only for scenarios not tagged @exec.
|
|
||||||
# We need a real process in a few cases: real program name, interactive usage…
|
|
||||||
Before('@exec') do
|
|
||||||
Aruba.process = Aruba::SpawnProcess
|
|
||||||
end
|
|
||||||
|
|
||||||
Before('~@exec') do
|
|
||||||
Aruba::InProcess.main_class = ArubaProgramWrapper
|
|
||||||
Aruba.process = Aruba::InProcess
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fake home directory for @fake_home tagged scenarios.
|
|
||||||
Before('@fake_home') do
|
|
||||||
ENV['HOME'] = File.expand_path(current_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Enable cucumber-sshd "fast" mode (persists sshd across scenarios), and
|
|
||||||
# register hooks for @sshd tagged scenarios.
|
|
||||||
Before do
|
|
||||||
@_sshd_fast = true
|
|
||||||
end
|
|
||||||
require 'cucumber/sshd/cucumber'
|
|
||||||
|
24
lib/producer/core/testing/aruba_program_wrapper.rb
Normal file
24
lib/producer/core/testing/aruba_program_wrapper.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module Producer
|
||||||
|
module Core
|
||||||
|
module Testing
|
||||||
|
class ArubaProgramWrapper
|
||||||
|
def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr,
|
||||||
|
kernel = Kernel)
|
||||||
|
@argv = argv
|
||||||
|
@stdin = stdin
|
||||||
|
@stdout = stdout
|
||||||
|
@stderr = stderr
|
||||||
|
@kernel = kernel
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute!
|
||||||
|
Producer::Core::CLI.run!(
|
||||||
|
@argv.dup, stdin: @stdin, stdout: @stdout, stderr: @stderr
|
||||||
|
)
|
||||||
|
rescue SystemExit => e
|
||||||
|
@kernel.exit e.status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
39
lib/producer/core/testing/cucumber.rb
Normal file
39
lib/producer/core/testing/cucumber.rb
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
require 'aruba/cucumber'
|
||||||
|
require 'aruba/in_process'
|
||||||
|
|
||||||
|
require 'producer/core'
|
||||||
|
require 'producer/core/testing/aruba_program_wrapper'
|
||||||
|
require 'producer/core/testing/cucumber/etc_steps'
|
||||||
|
require 'producer/core/testing/cucumber/execution_steps'
|
||||||
|
require 'producer/core/testing/cucumber/output_steps'
|
||||||
|
require 'producer/core/testing/cucumber/recipe_steps'
|
||||||
|
require 'producer/core/testing/cucumber/remote_steps'
|
||||||
|
require 'producer/core/testing/cucumber/ssh_steps'
|
||||||
|
|
||||||
|
# Raise aruba default timeout so test suite can run on a slow machine.
|
||||||
|
Before do
|
||||||
|
@aruba_timeout_seconds = 8
|
||||||
|
end
|
||||||
|
|
||||||
|
# Use aruba "in process" optimization only for scenarios not tagged @exec.
|
||||||
|
# We need a real process in a few cases: real program name, interactive usage…
|
||||||
|
Before('@exec') do
|
||||||
|
Aruba.process = Aruba::SpawnProcess
|
||||||
|
end
|
||||||
|
|
||||||
|
Before('~@exec') do
|
||||||
|
Aruba::InProcess.main_class = Producer::Core::Testing::ArubaProgramWrapper
|
||||||
|
Aruba.process = Aruba::InProcess
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fake home directory for @fake_home tagged scenarios.
|
||||||
|
Before('@fake_home') do
|
||||||
|
ENV['HOME'] = File.expand_path(current_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Enable cucumber-sshd "fast" mode (persists sshd across scenarios), and
|
||||||
|
# register hooks for @sshd tagged scenarios.
|
||||||
|
Before do
|
||||||
|
@_sshd_fast = true
|
||||||
|
end
|
||||||
|
require 'cucumber/sshd/cucumber'
|
Loading…
x
Reference in New Issue
Block a user