greybox 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/greybox.gemspec +1 -0
- data/lib/greybox/configurable.rb +5 -2
- data/lib/greybox/configuration.rb +1 -1
- data/lib/greybox/runner.rb +6 -2
- data/lib/greybox/version.rb +1 -1
- data/spec/configurable_spec.rb +81 -0
- data/spec/greybox_spec.rb +26 -0
- data/spec/runner_spec.rb +23 -9
- data/spec/spec_helper.rb +3 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a780147167dfd89d0dbb4bed3c7fcde9ab6ccf6
|
4
|
+
data.tar.gz: 9176c7343d521e112c2a0b161245853cf8597ed2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f56d4b162b73ccc4de3f4158a6246ab9d398ad9e669507d06db06a8493886e97d7e3700fd2937296bd089bcc285a3da8e9090e2be2619a9943c57e1ba7f06fa7
|
7
|
+
data.tar.gz: 783dd3ee57449158dbfc8e5bb5dbbb4dfff3c8a1d0b74bd2f7053b5c408085b03fcbd4fbac062c8f7b9369f7d3adda38a368f7724064bf953e674605b2afbc06
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/greybox.gemspec
CHANGED
data/lib/greybox/configurable.rb
CHANGED
@@ -3,7 +3,6 @@ module Greybox
|
|
3
3
|
attr_accessor :properties
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
attr_accessor :defaults
|
7
6
|
attr_accessor :required_properties
|
8
7
|
def def_property(name, args = {})
|
9
8
|
setter = "#{name}=".to_sym
|
@@ -32,6 +31,10 @@ module Greybox
|
|
32
31
|
include mod
|
33
32
|
end
|
34
33
|
|
34
|
+
def defaults
|
35
|
+
@defaults || {}
|
36
|
+
end
|
37
|
+
|
35
38
|
private
|
36
39
|
def new_blank_properties_module
|
37
40
|
Module.new do
|
@@ -50,7 +53,7 @@ module Greybox
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def get_prop(prop)
|
53
|
-
(@properties || {}).fetch(prop, self.class.defaults[prop])
|
56
|
+
(@properties || {}).fetch(prop, self.class.defaults[prop])
|
54
57
|
end
|
55
58
|
|
56
59
|
def verify
|
@@ -6,7 +6,7 @@ module Greybox
|
|
6
6
|
def_property :test_command, required: true
|
7
7
|
def_property :expected, default: ->(input) { input.gsub(/\.input$/, ".output") }
|
8
8
|
def_property :comparison, default: ->(actual, expected) { actual == expected }
|
9
|
-
def_property :blackbox_command
|
9
|
+
def_property :blackbox_command
|
10
10
|
|
11
11
|
end
|
12
12
|
end
|
data/lib/greybox/runner.rb
CHANGED
@@ -7,6 +7,7 @@ module Greybox
|
|
7
7
|
@config = config
|
8
8
|
@failures = []
|
9
9
|
end
|
10
|
+
|
10
11
|
def files
|
11
12
|
Dir.glob(config.input)
|
12
13
|
end
|
@@ -19,8 +20,11 @@ module Greybox
|
|
19
20
|
|
20
21
|
def expected_for(filename)
|
21
22
|
file = expected_filename(filename)
|
22
|
-
File.
|
23
|
-
|
23
|
+
unless File.exist?(file)
|
24
|
+
raise "No blackbox_command available to generate #{file}" unless config.blackbox_command
|
25
|
+
File.open(file, 'w') do |f|
|
26
|
+
f.write run_command(config.blackbox_command, filename)
|
27
|
+
end
|
24
28
|
end
|
25
29
|
File.read(file)
|
26
30
|
end
|
data/lib/greybox/version.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Greybox
|
2
|
+
describe Configurable do
|
3
|
+
|
4
|
+
def config
|
5
|
+
@config ||= configuration_class.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "the inserted module" do
|
9
|
+
it "shows what properties have been defined" do
|
10
|
+
cls = Class.new do
|
11
|
+
include Configurable
|
12
|
+
|
13
|
+
def_property :some_property
|
14
|
+
def_property :some_other_property
|
15
|
+
end
|
16
|
+
cls.ancestors.map(&:to_s).must_include "Properties(some_property, some_other_property)"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "setting a property" do
|
21
|
+
def configuration_class
|
22
|
+
Class.new do
|
23
|
+
include Configurable
|
24
|
+
|
25
|
+
def_property :regular
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "lets you set valid properties" do
|
30
|
+
config.regular = "abc"
|
31
|
+
config.regular.must_equal "abc"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not let you set invalid properties" do
|
35
|
+
-> do
|
36
|
+
config.unset = "abc"
|
37
|
+
end.must_raise NoMethodError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "required properties" do
|
42
|
+
def configuration_class
|
43
|
+
Class.new do
|
44
|
+
include Configurable
|
45
|
+
|
46
|
+
def_property :req, required: true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does not complain if the required property is set" do
|
51
|
+
config.req = "abc"
|
52
|
+
config.verify
|
53
|
+
end
|
54
|
+
|
55
|
+
it "complains if you do not set a property" do
|
56
|
+
-> do
|
57
|
+
config.verify
|
58
|
+
end.must_raise RuntimeError
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "default values" do
|
63
|
+
def configuration_class
|
64
|
+
Class.new do
|
65
|
+
include Configurable
|
66
|
+
|
67
|
+
def_property :with_default, default: 5
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "uses the default value" do
|
72
|
+
config.with_default.must_equal 5
|
73
|
+
end
|
74
|
+
|
75
|
+
it "lets you override the default" do
|
76
|
+
config.with_default = 6
|
77
|
+
config.with_default.must_equal 6
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/spec/greybox_spec.rb
CHANGED
@@ -8,5 +8,31 @@ module Greybox
|
|
8
8
|
end.must_raise RuntimeError
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
describe "running the tests" do
|
13
|
+
it "defers to runner to actually run the tests" do
|
14
|
+
Runner.any_instance.expects(:run)
|
15
|
+
Greybox.setup do |c|
|
16
|
+
c.input = "test/*.input"
|
17
|
+
c.test_command = "echo hi"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "printing the failures" do
|
23
|
+
it "prints out each failure" do
|
24
|
+
Diffy::Diff.stubs(:new).returns("-a\n+b\n")
|
25
|
+
$stdout.expects(:puts).with("FAILED:")
|
26
|
+
$stdout.expects(:puts).with("filename: a.input")
|
27
|
+
$stdout.expects(:puts).with("-a\n+b\n")
|
28
|
+
Runner.any_instance.stubs(:failures).returns([{filename: "a.input",
|
29
|
+
expected: "a",
|
30
|
+
actual: "b"}])
|
31
|
+
Greybox.setup do |c|
|
32
|
+
c.input = "test/*.input"
|
33
|
+
c.test_command = "echo hi"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
11
37
|
end
|
12
38
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -20,6 +20,7 @@ module Greybox
|
|
20
20
|
input: "*.input",
|
21
21
|
expected: ->(input) { "output_file" },
|
22
22
|
blackbox_command: "echo BLACKBOX_COMMAND",
|
23
|
+
test_command: "echo hi",
|
23
24
|
comparison: ->(actual, expected) { actual == expected },
|
24
25
|
}
|
25
26
|
end
|
@@ -65,16 +66,32 @@ module Greybox
|
|
65
66
|
end
|
66
67
|
|
67
68
|
it "uses the provided blackbox command to find the expected value for cases that don't have one yet" do
|
68
|
-
with_config(
|
69
|
-
blackbox_command: "echo output")
|
69
|
+
with_config(blackbox_command: "echo output")
|
70
70
|
runner.expects(:`).with "echo hi"
|
71
71
|
runner.expects(:`).with "echo output"
|
72
72
|
runner.run
|
73
73
|
end
|
74
74
|
|
75
|
+
it "does not run the command if the file already exists" do
|
76
|
+
with_config(blackbox_command: "echo output")
|
77
|
+
FileUtils.touch("output_file")
|
78
|
+
runner.expects(:`).with "echo hi"
|
79
|
+
runner.run
|
80
|
+
end
|
81
|
+
|
82
|
+
it "complains if there is no blackbox_command AND the file does not exist" do
|
83
|
+
with_config(blackbox_command: nil)
|
84
|
+
-> { runner.run }.must_raise RuntimeError
|
85
|
+
end
|
86
|
+
|
87
|
+
it "does not complain if there is no blackbox_command and the file DOES exist" do
|
88
|
+
with_config(blackbox_command: nil)
|
89
|
+
FileUtils.touch("output_file")
|
90
|
+
runner.run
|
91
|
+
end
|
92
|
+
|
75
93
|
it "inserts output filenames for %'s in the blackbox command" do
|
76
|
-
with_config(
|
77
|
-
blackbox_command: "echo output < %")
|
94
|
+
with_config(blackbox_command: "echo output < %")
|
78
95
|
runner.expects(:`).with "echo hi"
|
79
96
|
runner.expects(:`).with "echo output < inputfile.input"
|
80
97
|
runner.run
|
@@ -83,22 +100,19 @@ module Greybox
|
|
83
100
|
|
84
101
|
describe "asserting output" do
|
85
102
|
it "compares for equality by default" do
|
86
|
-
with_config(
|
87
|
-
blackbox_command: "echo hi")
|
103
|
+
with_config(blackbox_command: "echo hi")
|
88
104
|
runner.run
|
89
105
|
runner.failures.must_be_empty
|
90
106
|
end
|
91
107
|
|
92
108
|
it "has a failure if a test fails" do
|
93
|
-
with_config(
|
94
|
-
blackbox_command: "echo hello")
|
109
|
+
with_config(blackbox_command: "echo hello")
|
95
110
|
runner.run
|
96
111
|
runner.failures.wont_be_empty
|
97
112
|
end
|
98
113
|
|
99
114
|
it "compares by the provided comparison" do
|
100
115
|
with_config(comparison: ->(actual, expected) { actual == "hi\n" },
|
101
|
-
test_command: "echo hi",
|
102
116
|
blackbox_command: "echo hello")
|
103
117
|
runner.run
|
104
118
|
runner.failures.must_be_empty
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greybox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Jaffray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Test against a black box.
|
84
98
|
email:
|
85
99
|
- justin.jaffray@gmail.com
|
@@ -104,6 +118,7 @@ files:
|
|
104
118
|
- lib/greybox/configuration.rb
|
105
119
|
- lib/greybox/runner.rb
|
106
120
|
- lib/greybox/version.rb
|
121
|
+
- spec/configurable_spec.rb
|
107
122
|
- spec/greybox_spec.rb
|
108
123
|
- spec/runner_spec.rb
|
109
124
|
- spec/spec_helper.rb
|
@@ -132,6 +147,7 @@ signing_key:
|
|
132
147
|
specification_version: 4
|
133
148
|
summary: Easily test school assignments or other projects where you have a reference
|
134
149
|
test_files:
|
150
|
+
- spec/configurable_spec.rb
|
135
151
|
- spec/greybox_spec.rb
|
136
152
|
- spec/runner_spec.rb
|
137
153
|
- spec/spec_helper.rb
|