-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
env.rb
91 lines (81 loc) · 2.44 KB
/
env.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'aruba/cucumber'
require 'fileutils'
module ArubaExt
if defined?(Aruba::VERSION) && Aruba::VERSION >= '0.14.12'
def run_command(cmd, timeout = nil)
exec_cmd = cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd
unset_bundler_env_vars
# Ensure the correct Gemfile and binstubs are found
in_current_directory do
with_unbundled_env do
super(exec_cmd, timeout)
end
end
end
else
def run(cmd, timeout = nil)
exec_cmd = cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd
super(exec_cmd, timeout)
end
# This method overrides Aruba 0.5.4 implementation so that we can reset Bundler to use the sample app Gemfile
def in_current_dir(&block)
Bundler.with_clean_env do
_mkdir(current_dir)
Dir.chdir(current_dir, &block)
end
end
end
def unset_bundler_env_vars
empty_env = with_environment { with_unbundled_env { env_to_h } }
aruba_env = aruba.environment.to_h
(aruba_env.keys - empty_env.keys).each do |key|
delete_environment_variable key
end
empty_env.each do |k, v|
set_environment_variable k, v
end
end
def with_unbundled_env
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env { yield }
else
Bundler.with_clean_env { yield }
end
end
def env_to_h
if RUBY_VERSION > '2.0'
ENV.to_h
else
ENV.inject({}) { |h, (k, v)| h[k] = v; h }
end
end
end
if defined?(Aruba::VERSION) && Aruba::VERSION >= '0.14.12'
Aruba.configure do |config|
config.exit_timeout = 30
end
else
Before do
@aruba_timeout_seconds = 30
end
end
World(ArubaExt)
unless File.directory?('./tmp/example_app')
system "rake generate:app generate:stuff"
end
Before do
example_app_dir = 'tmp/example_app'
# Per default Aruba will create a directory tmp/aruba where it performs its file operations.
# https://github.com/cucumber/aruba/blob/v0.6.1/README.md#use-a-different-working-directory
aruba_dir = 'tmp/aruba'
# Remove the previous aruba workspace.
FileUtils.rm_rf(aruba_dir) if File.exist?(aruba_dir)
# We want fresh `example_app` project with empty `spec` dir except helpers.
# FileUtils.cp_r on Ruby 1.9.2 doesn't preserve permissions.
system('cp', '-r', example_app_dir, aruba_dir)
helpers = %w[spec/spec_helper.rb spec/rails_helper.rb]
Dir["#{aruba_dir}/spec/*"].each do |path|
next if helpers.any? { |helper| path.end_with?(helper) }
FileUtils.rm_rf(path)
end
end