cog-rb 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/cog/version.rb +1 -1
- data/lib/rspec/cog/setup.rb +74 -71
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ecf2692d6236c91b5f90a0e4acae34191e67959
|
4
|
+
data.tar.gz: 4c36954c1a905479360952f03a8ec1490ab74b15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 887b6031722158ba5742b05a2b159509eaa03284f8eeaff83fc3fd167c3f161da7652fb9014b2efd357b1fc8c66ff7da3829c4a052e4d71c6f455aa8b91917af
|
7
|
+
data.tar.gz: a5ddfadd53303282b851ef21dad519c7d8d57d593d3406df107a20683a92bd78029987f3d70431275f036e1a6a34dfdaef1b27cda718cdce206b9d07333b8f62
|
data/CHANGELOG.md
CHANGED
data/lib/cog/version.rb
CHANGED
data/lib/rspec/cog/setup.rb
CHANGED
@@ -2,77 +2,80 @@ require 'yaml'
|
|
2
2
|
require 'securerandom'
|
3
3
|
require 'rspec/core'
|
4
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
|
-
|
5
|
+
class Cog
|
6
|
+
module RSpec
|
7
|
+
module Setup
|
8
|
+
extend ::RSpec::SharedContext
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
# Ensure a clean ENV, as far as Cog cares
|
12
|
+
# NOTE: Does not do anything pertaining to dynamic config
|
13
|
+
# variables yet
|
14
|
+
ENV.delete_if{|name, value| name.start_with?("COG_")}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:base_dir) do
|
18
|
+
# Cog Ruby commands expect to be run from a script in the
|
19
|
+
# top-level directory. This code thus assumes that the tests are
|
20
|
+
# being run from that same top-level directory.
|
21
|
+
File.absolute_path(Dir.pwd)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:config_file) do
|
25
|
+
File.join(base_dir, "config.yaml")
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:bundle_name) do
|
29
|
+
# Read the bundle name from the bundle configuration; no need to
|
30
|
+
# repeat that everywhere
|
31
|
+
YAML.load(File.read(config_file))["name"]
|
32
|
+
end
|
33
|
+
|
34
|
+
let!(:bundle) do
|
35
|
+
# This is `let!` instead of `let` because this call actually
|
36
|
+
# *creates* the bundle module that our commands live in; we want
|
37
|
+
# to ensure that this gets called before we start doing anything else
|
38
|
+
Cog::Bundle.new(bundle_name, base_dir: base_dir)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:command_name){ raise "Must supply a :command_name!" }
|
42
|
+
|
43
|
+
let(:command) do
|
44
|
+
bundle.command_instance(command_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:invocation_id) { SecureRandom.uuid }
|
48
|
+
|
49
|
+
let(:service_root) { "http://localhost:4002" }
|
50
|
+
|
51
|
+
let(:cog_env) { [] }
|
52
|
+
|
53
|
+
def run_command(args: [], options: {})
|
54
|
+
ENV["COG_COMMAND"] = command_name
|
55
|
+
ENV["COG_INVOCATION_ID"] = invocation_id
|
56
|
+
ENV["COG_SERVICES_ROOT"] = service_root
|
57
|
+
|
58
|
+
# populate arguments
|
59
|
+
ENV["COG_ARGC"] = args.size.to_s
|
60
|
+
args.each_with_index{|arg, i| ENV["COG_ARGV_#{i}"] = arg.to_s}
|
61
|
+
|
62
|
+
# populate_options
|
63
|
+
if !options.keys.empty?
|
64
|
+
ENV["COG_OPTS"] = options.keys.join(",")
|
65
|
+
options.each{|k,v| ENV["COG_OPT_#{k.upcase}"] = v.to_s}
|
66
|
+
end
|
67
|
+
|
68
|
+
# TODO: receive a single input on request(:input) and
|
69
|
+
# multiple for :fetch_input
|
70
|
+
|
71
|
+
# Expose previous inputs on request.input
|
72
|
+
# We use allow because not all commands receive input
|
73
|
+
allow(command.request).to receive(:input).and_return(cog_env)
|
74
|
+
|
75
|
+
# Use allow because not all commands will need to do this
|
76
|
+
allow(command).to receive(:fetch_input).and_return(cog_env)
|
77
|
+
command.run_command
|
78
|
+
end
|
64
79
|
end
|
65
|
-
|
66
|
-
# TODO: receive a single input on request(:input) and
|
67
|
-
# multiple for :fetch_input
|
68
|
-
|
69
|
-
# Expose previous inputs on request.input
|
70
|
-
# We use allow because not all commands receive input
|
71
|
-
allow(command.request).to receive(:input).and_return(cog_env)
|
72
|
-
|
73
|
-
# Use allow because not all commands will need to do this
|
74
|
-
allow(command).to receive(:fetch_input).and_return(cog_env)
|
75
|
-
command.run_command
|
76
80
|
end
|
77
|
-
|
78
81
|
end
|