cog-rb 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cog/command.rb +5 -3
- data/lib/cog/exceptions.rb +4 -0
- data/lib/cog/version.rb +1 -1
- data/lib/rspec/cog.rb +4 -0
- data/lib/rspec/cog/matchers.rb +17 -0
- data/lib/rspec/cog/setup.rb +76 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 198ee7dcc7e2ffe311fd27f2d69c8073c57f0d28
|
4
|
+
data.tar.gz: 460812701e1b25690b48c71fc51fc9b6de67b24d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbca4897dbe208a38ada307dd7e40c4d53263e5e28aa80037ad6ebda3abfd38341989393cbe5657ea037092303bba26bd2e9d0e068fdaf1569e3cf52f90708eb
|
7
|
+
data.tar.gz: d8d646b04325f58f792a260b28324efede5c705976fbfec45ae9b2606390d2a2d6981a86cbc7115ca661d2c097c4fa5e84e013172f64a2ede7c9b06a6e9dfe36
|
data/lib/cog/command.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
1
|
require 'json'
|
2
|
+
require 'cog/exceptions'
|
3
3
|
|
4
4
|
class Cog
|
5
5
|
class Command
|
@@ -38,6 +38,9 @@ class Cog
|
|
38
38
|
accumulate_input if config[:input] == :accumulate
|
39
39
|
run_command
|
40
40
|
response.send
|
41
|
+
rescue Cog::Error => e
|
42
|
+
STDERR.puts(e.message)
|
43
|
+
exit 1
|
41
44
|
end
|
42
45
|
|
43
46
|
def env_var(var, suffix: nil, required: false, failure_message: nil)
|
@@ -53,8 +56,7 @@ class Cog
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def fail(message)
|
56
|
-
|
57
|
-
exit 1
|
59
|
+
raise Cog::Error, message
|
58
60
|
end
|
59
61
|
|
60
62
|
def self.input(value=nil)
|
data/lib/cog/version.rb
CHANGED
data/lib/rspec/cog.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This is what you want to use for commands that return raw text
|
2
|
+
RSpec::Matchers.define :respond_with_text do |expected|
|
3
|
+
match do |command|
|
4
|
+
@actual = command.response.content["body"]
|
5
|
+
@actual == expected
|
6
|
+
end
|
7
|
+
diffable
|
8
|
+
end
|
9
|
+
|
10
|
+
# Use this when dealing with commands that return data structures
|
11
|
+
RSpec::Matchers.define :respond_with do |expected|
|
12
|
+
match do |command|
|
13
|
+
@actual = command.response.content
|
14
|
+
@actual == expected
|
15
|
+
end
|
16
|
+
diffable
|
17
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'rspec/core'
|
4
|
+
|
5
|
+
module Cog::RSpec::Setup
|
6
|
+
extend RSpec::SharedContext
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
# Ensure a clean ENV, as far as Cog cares
|
10
|
+
# NOTE: Does not do anything pertaining to dynamic config
|
11
|
+
# variables yet
|
12
|
+
ENV.delete_if{|name, value| name.start_with?("COG_")}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:base_dir) do
|
16
|
+
# Cog Ruby commands expect to be run from a script in the
|
17
|
+
# top-level directory. This code thus assumes that the tests are
|
18
|
+
# being run from that same top-level directory.
|
19
|
+
File.absolute_path(Dir.pwd)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:config_file) do
|
23
|
+
File.join(base_dir, "config.yaml")
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:bundle_name) do
|
27
|
+
# Read the bundle name from the bundle configuration; no need to
|
28
|
+
# repeat that everywhere
|
29
|
+
YAML.load(File.read(config_file))["name"]
|
30
|
+
end
|
31
|
+
|
32
|
+
let!(:bundle) do
|
33
|
+
# This is `let!` instead of `let` because this call actually
|
34
|
+
# *creates* the bundle module that our commands live in; we want
|
35
|
+
# to ensure that this gets called before we start doing anything else
|
36
|
+
Cog::Bundle.new(bundle_name, base_dir: base_dir, config_file: config_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:command_name){ raise "Must supply a :command_name!" }
|
40
|
+
|
41
|
+
let(:command) do
|
42
|
+
Object.const_get("CogCmd::#{bundle_name.capitalize}::#{command_name.capitalize}").new
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:invocation_id) { SecureRandom.uuid }
|
46
|
+
|
47
|
+
let(:service_root) { "http://localhost:4002" }
|
48
|
+
|
49
|
+
let(:cog_env) { [] }
|
50
|
+
|
51
|
+
def run_command(args: [], options: {})
|
52
|
+
ENV["COG_COMMAND"] = command_name
|
53
|
+
ENV["COG_INVOCATION_ID"] = invocation_id
|
54
|
+
ENV["COG_SERVICES_ROOT"] = service_root
|
55
|
+
|
56
|
+
# populate arguments
|
57
|
+
ENV["COG_ARGC"] = args.size.to_s
|
58
|
+
args.each_with_index{|arg, i| ENV["COG_ARGV_#{i}"] = arg.to_s}
|
59
|
+
|
60
|
+
# populate_options
|
61
|
+
if !options.keys.empty?
|
62
|
+
ENV["COG_OPTS"] = options.keys.join(",")
|
63
|
+
options.each{|k,v| ENV["COG_OPT_#{k.upcase}"] = v.to_s}
|
64
|
+
end
|
65
|
+
|
66
|
+
# TODO: receive a single input on STDIN, multiple for :fetch_input
|
67
|
+
|
68
|
+
# Expose previous inputs on STDIN
|
69
|
+
expect(STDIN).to receive(:read).and_return(cog_env.to_json)
|
70
|
+
|
71
|
+
# Use allow because not all commands will need to do this
|
72
|
+
allow(command).to receive(:fetch_input).and_return(cog_env)
|
73
|
+
command.run_command
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cog-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Imbriaco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,12 +48,16 @@ files:
|
|
48
48
|
- lib/cog/bundle.rb
|
49
49
|
- lib/cog/command.rb
|
50
50
|
- lib/cog/config.rb
|
51
|
+
- lib/cog/exceptions.rb
|
51
52
|
- lib/cog/request.rb
|
52
53
|
- lib/cog/response.rb
|
53
54
|
- lib/cog/service.rb
|
54
55
|
- lib/cog/services/memory.rb
|
55
56
|
- lib/cog/services/metadata.rb
|
56
57
|
- lib/cog/version.rb
|
58
|
+
- lib/rspec/cog.rb
|
59
|
+
- lib/rspec/cog/matchers.rb
|
60
|
+
- lib/rspec/cog/setup.rb
|
57
61
|
homepage: https://github.com/cog-bundles/cog-rb
|
58
62
|
licenses: []
|
59
63
|
metadata: {}
|
@@ -78,3 +82,4 @@ signing_key:
|
|
78
82
|
specification_version: 4
|
79
83
|
summary: Cog command helper library
|
80
84
|
test_files: []
|
85
|
+
has_rdoc:
|