command-unit 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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2YxZTJjNGQzMGNlMWU5ODdjN2U4MTMyYmQ1NWQ4YTQ3ZDQ1N2MzOQ==
4
+ YmNiYmM2MjU5Y2M4ZGY0ZTU4ZTgwNDYyMmUxMDgxNTIxMDJiZmM1NQ==
5
5
  data.tar.gz: !binary |-
6
- M2RhYjRmMTM3ZDQyNmViNWY3N2RjMTY0Y2EyMTdhMTRhYjUyZjI4Ng==
6
+ MWMyZTc3N2FjNWMxZjcwMzNlNWI4YWU5ZjNkMDc5ZTFjM2U2M2UyMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2FhYWYzZDE3OGE3OTFjMmFkZWMxYmE0NTRmMTZhMWMzZGYxYjVmOWE5YjM4
10
- N2ExYmI2NWEyOTNkZWUyNzdiMmU3MDU2ZDU2NzY2NDE1YmZhMzdlZWFlNzdh
11
- OTZhNTZkOGVjNDY5NzBmOWNlMTc2OWIxY2U1MDVjMDU0NzY2ZTg=
9
+ MDRhZGRkMDM0N2RhNzU3ZTRlZmQ3YjU1OTAwZmQxMmU0NmExOTFlMjc4NjUy
10
+ ODhjYjYyMmJhYjVmMjQ5Y2I1MjBkMWRhMjU3ZDgzYzA3MWY3MTI5MDkxMzI0
11
+ M2RhYjkyYjE5YjMxODk0NTZhMTQ3MTFkNTA1Nzc5YzAwNjY3ZTU=
12
12
  data.tar.gz: !binary |-
13
- NjlmYjUyZTk3NTc5ZjA0MzU2Y2IyYmYwNmUwYmU3ODY1MmZkOGE1ZWE2ZjQ1
14
- NmYzNTkzMjk2Y2Y0OWEyMzNiOTFlNWIxNjViOTI5YTVjZGI0ZWRmNmIxZGJm
15
- MGE2MTU2MGJjNDgxOTg4MTc4MWNiZmI2Nzc2ZDM2YjhjODUwN2Q=
13
+ NjVlODMyMmEwMDUzZTljZjA5Y2FjMzVmZmE0Y2FiMWZmMDhjODllYTUxZDU5
14
+ NzVjN2YxNDkzNzhjOWE2ODY3ZjA5MzcyYjdmMWE5NTQ3ZThmMTM3NzMxOTc2
15
+ M2QxNzgzN2JjZDJlMjZkYzcyMDYzNzBkNDNiMTM4YWExZmE5NWE=
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.gem
2
2
  .idea
3
- *.iml
3
+ *.iml
4
+ .DS_Store
data/changelog.md ADDED
@@ -0,0 +1,10 @@
1
+ # Command Unit changelog
2
+
3
+ - 0.0.2 lots of changes:
4
+ * More useful output:
5
+ - Colours
6
+ - Totals
7
+ * Namespaces to help with splitting up tests
8
+ * More self-tests
9
+ - 0.0.1 some basic assertions
10
+ - 0.0.0 initial release
data/command-unit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "command-unit"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.author = "Samuel R. Salisbury"
6
6
  s.email = "samsalisbury@gmail.com"
@@ -0,0 +1,11 @@
1
+ module CommandUnit
2
+
3
+ class Expectation
4
+ def initialize(expectation_text, &expectaton_block)
5
+ @desc = expectation_text
6
+ @block = expectaton_block
7
+ end
8
+ attr_accessor :desc, :block
9
+ end
10
+
11
+ end
@@ -0,0 +1,14 @@
1
+ module CommandUnit
2
+
3
+ class ExpectationResult
4
+ def initialize(description, expectation_met)
5
+ @message = description
6
+ @success = expectation_met
7
+ end
8
+ attr_reader :message
9
+ def success?
10
+ @success
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,7 @@
1
+ module CommandUnit
2
+
3
+ class Hooks
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'totaliser'
2
+
3
+ module CommandUnit
4
+
5
+ class Hooks
6
+
7
+ def initialize
8
+ @before_scenario = []
9
+ @scenario_pass = []
10
+ @scenario_fail = []
11
+ @after_scenario = []
12
+ @before_test = []
13
+ @test_pass = []
14
+ @test_fail = []
15
+ @after_test = []
16
+ @before_expectation = []
17
+ @expectation_pass = []
18
+ @expectation_fail = []
19
+ @after_expectation = []
20
+ # Note: I know this is a smell, just trying to get tests passing...
21
+ # Looks ripe for inheriting the hooks, and passing in a composition
22
+ # of all hooks to the test runner...
23
+ @totaliser = Totaliser.new
24
+ add :before_scenario do totaliser.scenario_run end
25
+ add :scenario_pass do totaliser.scenario_pass end
26
+ add :scenario_fail do totaliser.scenario_fail end
27
+ add :before_test do totaliser.test_run end
28
+ add :test_pass do totaliser.test_pass end
29
+ add :test_fail do totaliser.test_fail end
30
+ add :before_expectation do totaliser.expectation_run end
31
+ add :expectation_pass do totaliser.expectation_pass end
32
+ add :expectation_fail do totaliser.expectation_fail end
33
+ end
34
+
35
+ attr_reader :totaliser,
36
+ :before_scenario, :scenario_pass, :scenario_fail, :after_scenario,
37
+ :before_test, :test_pass, :test_fail, :after_test,
38
+ :before_expectation, :expectation_pass, :expectation_fail, :after_expectation
39
+
40
+ def add(event_name, &handler)
41
+ raise "CommandUnit::Hooks.add No such event '#{event_name}'" unless self.respond_to? event_name
42
+ handlers = instance_variable_get "@#{event_name}"
43
+ handlers.push handler
44
+ end
45
+
46
+ def fire(event_name)
47
+ raise "CommandUnit::Hooks.fire No such event '#{event_name}'" unless self.respond_to? event_name
48
+ handlers = instance_variable_get "@#{event_name}"
49
+ handlers.each do |handler|
50
+ handler.call
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,106 @@
1
+ require_relative '../string/console_colours'
2
+
3
+ module CommandUnit
4
+
5
+ class Scenario
6
+ def initialize(namespace, desc, out_stream, &block)
7
+ @out_stream = out_stream
8
+ @namespace = namespace
9
+ @id = @@scenario_count += 1
10
+ @desc = desc
11
+ @block = block
12
+ @set_up_block = nil
13
+ @tests = []
14
+ @current_test = nil
15
+ @tear_down_block = nil
16
+ @scenario_set_up_block = nil
17
+ @scenario_tear_down_block = nil
18
+ @tests_run = 0
19
+ @expectations_run = 0
20
+ @expectations_met = 0
21
+ @expectations_not_met = 0
22
+ @inconclusive_expectations = 0
23
+ end
24
+
25
+ def run(hooks, out_stream=@out_stream)
26
+ raise "CommandUnit::Scenario.run hooks must be of type Hooks" unless hooks.is_a? Hooks
27
+ hooks.fire(:before_scenario)
28
+ scenario_failed = false
29
+ out_stream.puts "\nRunning scenario #{@id}: #{@desc}"
30
+ @@current_scenario = self
31
+ @block.call
32
+ context = {}
33
+ @scenario_set_up_block.call(context) unless @scenario_set_up_block.nil?
34
+ @tests.each do |test|
35
+ hooks.fire(:before_test)
36
+ test_failed = false
37
+ out_stream.puts "\tWhen I #{test.when_i_text}"
38
+ @tests_run += 1
39
+ @set_up_block.call(context) unless @set_up_block.nil?
40
+ test.when_i_block.call(context) unless test.when_i_block.nil?
41
+ test.expectations.each do |expectation|
42
+ hooks.fire :before_expectation
43
+ out_stream.print "\t\tI expect #{expectation.desc}..."
44
+ result = expectation.block.call(context)
45
+ @expectations_run += 1
46
+ if result.respond_to? :success?
47
+ if result.success?
48
+ hooks.fire :expectation_pass
49
+ @expectations_met +=1
50
+ out_stream.puts "Success! #{result.message}".console_green
51
+ else
52
+ hooks.fire :expectation_fail
53
+ test_failed = true
54
+ scenario_failed = true
55
+ @expectations_not_met +=1
56
+ out_stream.puts "Failure!".console_red
57
+ out_stream.puts result.message
58
+ end
59
+ else
60
+ test_failed = true
61
+ @inconclusive_expectations += 1
62
+ out_stream.puts "Inconclusive! #{result}".console_yellow
63
+ end
64
+ hooks.fire :after_expectation
65
+ end
66
+ if test_failed
67
+ hooks.fire :test_fail
68
+ else
69
+ hooks.fire :test_pass
70
+ end
71
+
72
+ hooks.fire :after_test
73
+ @tear_down_block.call(context) unless @tear_down_block.nil?
74
+ end
75
+
76
+ if scenario_failed
77
+ hooks.fire :scenario_fail
78
+ else
79
+ hooks.fire :scenario_pass
80
+ end
81
+
82
+ hooks.fire :after_scenario
83
+ @scenario_tear_down_block.call(context) unless @scenario_tear_down_block.nil?
84
+ @@current_scenario = nil
85
+
86
+ colour = @expectations_not_met == 0 ? String::CONSOLE_GREEN : String::CONSOLE_RED
87
+
88
+ out_stream.puts "Scenario #{@id} finished, #{@tests_run} tests, #{@expectations_run} expectations with #{@expectations_met} successful and #{@expectations_not_met} failures.".console_colour(colour)
89
+ end
90
+
91
+ def run_silent(hooks)
92
+ buffer = StringIO.new
93
+ run(hooks, buffer)
94
+ return buffer.string
95
+ end
96
+
97
+ def add_test(test)
98
+ @tests.push test
99
+ @current_test = test
100
+ end
101
+
102
+ attr_accessor :desc, :block, :set_up_block, :tests, :tear_down_block, :current_test,
103
+ :scenario_set_up_block, :scenario_tear_down_block, :namespace, :out
104
+ end
105
+
106
+ end
@@ -0,0 +1,15 @@
1
+ module CommandUnit
2
+
3
+ class Test
4
+ def initialize(when_i_text, &when_i_block)
5
+ @when_i_text = when_i_text
6
+ @when_i_block = when_i_block
7
+ @expectations = []
8
+ end
9
+ attr_reader :when_i_text, :when_i_block, :expectations
10
+ def add_expectation(expectation)
11
+ @expectations.push expectation
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,55 @@
1
+ module CommandUnit
2
+ class Totaliser
3
+ def initialize
4
+ @scenarios_run = 0
5
+ @scenarios_passed = 0
6
+ @scenarios_failed = 0
7
+ @tests_run = 0
8
+ @tests_passed = 0
9
+ @tests_failed = 0
10
+ @expectations_run = 0
11
+ @expectations_passed = 0
12
+ @expectations_failed = 0
13
+ end
14
+
15
+ def scenario_run
16
+ @scenarios_run += 1
17
+ end
18
+
19
+ def scenario_pass
20
+ @scenarios_passed += 1
21
+ end
22
+
23
+ def scenario_fail
24
+ @scenarios_failed += 1
25
+ end
26
+
27
+ def test_run
28
+ @tests_run += 1
29
+ end
30
+
31
+ def test_pass
32
+ @tests_passed += 1
33
+ end
34
+
35
+ def test_fail
36
+ @tests_failed += 1
37
+ end
38
+
39
+ def expectation_run
40
+ @expectations_run += 1
41
+ end
42
+
43
+ def expectation_pass
44
+ @expectations_passed += 1
45
+ end
46
+
47
+ def expectation_fail
48
+ @expectations_failed += 1
49
+ end
50
+
51
+ attr_reader :scenarios_run, :scenarios_passed, :scenarios_failed,
52
+ :tests_run, :tests_passed, :tests_failed,
53
+ :expectations_run, :expectations_passed, :expectations_failed
54
+ end
55
+ end
data/lib/command-unit.rb CHANGED
@@ -1,3 +1,10 @@
1
+ require 'stringio'
2
+ require_relative 'command-unit/scenario'
3
+ require_relative 'command-unit/test'
4
+ require_relative 'command-unit/expectation'
5
+ require_relative 'command-unit/expectation_result'
6
+ require_relative 'command-unit/hooks'
7
+
1
8
  module CommandUnit
2
9
 
3
10
  @@scenario_count = 0
@@ -18,40 +25,46 @@ module CommandUnit
18
25
  namespace = namespace_or_description
19
26
  end
20
27
 
21
- @@scenarios.push Scenario.new(namespace, description, &block)
28
+ @@scenarios.push Scenario.new(namespace, description, STDOUT, &block)
29
+
22
30
  return @@scenarios.last
23
31
  end
24
32
 
25
- def run(namespace_or_scenario_or_nowt = nil)
33
+ def run_silent(namespace_or_nil=nil)
34
+ output = StringIO.new
35
+ run(namespace_or_nil, output)
36
+ return output.string
37
+ end
38
+
39
+ def run(namespace_or_scenario_or_nowt=nil, out_stream=STDOUT)
40
+ hooks = Hooks.new
26
41
  if namespace_or_scenario_or_nowt.nil?
27
42
  # Run the lot...
43
+ out_stream.puts "\nRunning #{@@scenarios.count} scenarios..."
28
44
  @@scenarios.each do |scenario|
29
- scenario.run
45
+ scenario.run(hooks, out_stream)
30
46
  end
31
47
  else
32
48
  if namespace_or_scenario_or_nowt.is_a? Symbol
33
- @@scenarios.each do |scenario|
34
- next unless scenario.namespace == namespace_or_scenario_or_nowt
35
- scenario.run
49
+ namespace = namespace_or_scenario_or_nowt
50
+ scenarios_in_namespace = @@scenarios.select { |s| s.namespace == namespace }
51
+ out_stream.puts "\nRunning #{scenarios_in_namespace.length} scenarios in namespace '#{namespace}'..."
52
+ scenarios_in_namespace.each do |scenario|
53
+ scenario.run(hooks, out_stream)
36
54
  end
37
55
  elsif namespace_or_scenario.is_a? Scenario
38
- namespace_or_scenario_or_nowt.run
56
+ scenario = namespace_or_scenario
57
+ out_stream.puts "\nRunning single scenario..."
58
+ scenario.run(hooks, out_stream)
39
59
  else
40
60
  raise "You must pass either a Scenario, a Symbol (namespace), or nil into run. You passed a #{namespace_or_scenario_or_nowt.class}"
41
61
  end
42
62
  end
43
- end
44
63
 
45
- require 'stringio'
64
+ t = hooks.totaliser
65
+ message = "\nRan #{t.scenarios_run} scenarios, #{t.scenarios_passed} passed, #{t.scenarios_failed} failed (tests passed: #{t.tests_passed}, failed: #{t.tests_failed}) (expectations passed: #{t.expectations_passed}, failed: #{t.expectations_failed})\n"
46
66
 
47
- def capture_stdout
48
- out = StringIO.new
49
- $stdout = out
50
- yield
51
- r = out.string
52
- return r
53
- ensure
54
- $stdout = STDOUT
67
+ out_stream.puts message
55
68
  end
56
69
 
57
70
  def ensure_inside_scenario
@@ -88,107 +101,12 @@ module CommandUnit
88
101
  @@current_scenario.current_test.add_expectation Expectation.new(desc, &i_expect_block)
89
102
  end
90
103
 
91
- def success(desc = '')
104
+ def pass(desc = '')
92
105
  ExpectationResult.new(desc, true)
93
106
  end
94
107
 
95
- def failure(desc = '')
108
+ def fail(desc = '')
96
109
  ExpectationResult.new(desc, false)
97
110
  end
98
111
 
99
- class Scenario
100
- def initialize(namespace, desc, &block)
101
- @namespace = namespace
102
- @id = @@scenario_count += 1
103
- @desc = desc
104
- @block = block
105
- @set_up_block = nil
106
- @tests = []
107
- @current_test = nil
108
- @tear_down_block = nil
109
- @scenario_set_up_block = nil
110
- @scenario_tear_down_block = nil
111
- @tests_run = 0
112
- @expectations_run = 0
113
- @expectations_met = 0
114
- @expectations_not_met = 0
115
- @inconclusive_expectations = 0
116
- end
117
-
118
- def run
119
- puts "\nRunning scenario #{@id}: #{@desc}"
120
- @@current_scenario = self
121
- @block.call
122
- context = {}
123
- @scenario_set_up_block.call(context) unless @scenario_set_up_block.nil?
124
- @tests.each do |test|
125
- puts "\tWhen I #{test.when_i_text}"
126
- @tests_run += 1
127
- @set_up_block.call(context) unless @set_up_block.nil?
128
- test.when_i_block.call(context) unless test.when_i_block.nil?
129
- test.expectations.each do |expectation|
130
- print "\t\tI expect #{expectation.desc}..."
131
- result = expectation.block.call(context)
132
- @expectations_run += 1
133
- if result.respond_to? :success?
134
- if result.success?
135
- @expectations_met +=1
136
- puts "Success! #{result.message}"
137
- else
138
- @expectations_not_met +=1
139
- puts "Failure! #{result.message}"
140
- end
141
- else
142
- @inconclusive_expectations += 1
143
- puts "Inconclusive! #{result}"
144
- end
145
- end
146
- @tear_down_block.call(context) unless @tear_down_block.nil?
147
- end
148
- @scenario_tear_down_block.call(context) unless @scenario_tear_down_block.nil?
149
- @@current_scenario = nil
150
-
151
- puts "Scenario #{@id} finished, #{@tests_run} tests, #{@expectations_run} expectations with #{@expectations_met} successful and #{@expectations_not_met} failures."
152
- end
153
-
154
- def add_test(test)
155
- @tests.push test
156
- @current_test = test
157
- end
158
-
159
- attr_accessor :desc, :block, :set_up_block, :tests, :tear_down_block, :current_test,
160
- :scenario_set_up_block, :scenario_tear_down_block, :namespace
161
- end
162
-
163
- class Test
164
- def initialize(when_i_text, &when_i_block)
165
- @when_i_text = when_i_text
166
- @when_i_block = when_i_block
167
- @expectations = []
168
- end
169
- attr_reader :when_i_text, :when_i_block, :expectations
170
- def add_expectation(expectation)
171
- @expectations.push expectation
172
- end
173
- end
174
-
175
- class Expectation
176
- def initialize(expectation_text, &expectaton_block)
177
- @desc = expectation_text
178
- @block = expectaton_block
179
- end
180
- attr_accessor :desc, :block
181
- end
182
-
183
- class ExpectationResult
184
- def initialize(description, expectation_met)
185
- @message = description
186
- @success = expectation_met
187
- end
188
- attr_reader :message
189
- def success?
190
- @success
191
- end
192
-
193
- end
194
112
  end
@@ -0,0 +1,21 @@
1
+ class String
2
+ def console_colour(colour_code)
3
+ "\e[#{colour_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def console_red
7
+ console_colour(CONSOLE_RED)
8
+ end
9
+
10
+ def console_green
11
+ console_colour(CONSOLE_GREEN)
12
+ end
13
+
14
+ def console_yellow
15
+ console_colour(CONSOLE_YELLOW)
16
+ end
17
+
18
+ CONSOLE_RED = 31
19
+ CONSOLE_GREEN = 32
20
+ CONSOLE_YELLOW = 33
21
+ end
@@ -0,0 +1,20 @@
1
+ include CommandUnit
2
+
3
+ scenario :command_unit, 'Running a scenario with no tests or assertions' do
4
+
5
+ when_i 'execute the scenario' do |context|
6
+ context[:scenario] = scenario 'This is an empty scenario' do
7
+
8
+ end
9
+ context[:out] = context[:scenario].run_silent(Hooks.new)
10
+ end
11
+
12
+ i_expect 'to see the scenario title' do |context|
13
+ if context[:out].include? 'This is an empty scenario'
14
+ pass
15
+ else
16
+ fail "Output was: '#{context[:out]}'"
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,52 @@
1
+ include CommandUnit
2
+
3
+ scenario :command_unit, 'Running a scenario with 1 test and 1 failing assertion from CommandUnit::run' do
4
+
5
+ set_up do
6
+ scenario :one_test_one_failing_expectation, 'This is the one scenario' do
7
+ when_i 'this is the one test' do
8
+ # Nowt ;)
9
+ end
10
+ i_expect 'this is the one expectation' do
11
+ fail
12
+ end
13
+ end
14
+ end
15
+
16
+ when_i 'run the one scenario' do |context|
17
+ context[:out] = run_silent :one_test_one_failing_expectation
18
+ end
19
+
20
+ i_expect 'to see the when_i text' do |context|
21
+ if context[:out].include? 'this is the one test'
22
+ pass
23
+ else
24
+ fail
25
+ end
26
+ end
27
+
28
+ i_expect 'to see the i_expect text' do |context|
29
+ if context[:out].include? 'this is the one expectation'
30
+ pass
31
+ else
32
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
33
+ end
34
+ end
35
+
36
+ i_expect 'to see the correct number of tests and expectations of the scenario reported' do |context|
37
+ if context[:out].include? '1 tests, 1 expectations with 0 successful and 1 failures'
38
+ pass
39
+ else
40
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
41
+ end
42
+ end
43
+
44
+ i_expect 'to see the total number of run scenarios and totals' do |context|
45
+ if context[:out].include? 'Ran 1 scenarios, 0 passed, 1 failed (tests passed: 0, failed: 1) (expectations passed: 0, failed: 1)'
46
+ pass
47
+ else
48
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,52 @@
1
+ include CommandUnit
2
+
3
+ scenario :command_unit, 'Running a scenario with 1 test and 1 passing assertion from CommandUnit::run' do
4
+
5
+ set_up do
6
+ scenario :one_test_one_passing_expectation, 'This is the one scenario' do
7
+ when_i 'this is the one test' do
8
+ # Nowt ;)
9
+ end
10
+ i_expect 'this is the one expectation' do
11
+ pass
12
+ end
13
+ end
14
+ end
15
+
16
+ when_i 'run the one scenario' do |context|
17
+ context[:out] = run_silent :one_test_one_passing_expectation
18
+ end
19
+
20
+ i_expect 'to see the when_i text' do |context|
21
+ if context[:out].include? 'this is the one test'
22
+ pass
23
+ else
24
+ fail
25
+ end
26
+ end
27
+
28
+ i_expect 'to see the i_expect text' do |context|
29
+ if context[:out].include? 'this is the one expectation'
30
+ pass
31
+ else
32
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
33
+ end
34
+ end
35
+
36
+ i_expect 'to see the correct number of tests and expectations of the scenario reported' do |context|
37
+ if context[:out].include? '1 tests, 1 expectations with 1 successful and 0 failures'
38
+ pass
39
+ else
40
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
41
+ end
42
+ end
43
+
44
+ i_expect 'to see the total number of run scenarios and totals' do |context|
45
+ if context[:out].include? 'Ran 1 scenarios, 1 passed, 0 failed (tests passed: 1, failed: 0) (expectations passed: 1, failed: 0)'
46
+ pass
47
+ else
48
+ fail "\n\n=====\n\n#{context[:out]}\n\n=====\n\n"
49
+ end
50
+ end
51
+
52
+ end
data/test/test.rb CHANGED
@@ -2,58 +2,8 @@ require_relative '../lib/command-unit'
2
2
 
3
3
  include CommandUnit
4
4
 
5
- scenario :command_unit, 'Running a scenario with no tests or assertions' do
6
-
7
- when_i 'execute the scenario' do |context|
8
- context[:scenario] = scenario 'This is an empty scenario' do
9
-
10
- end
11
- context[:out] = capture_stdout { context[:scenario].run }
12
- end
13
-
14
- i_expect 'to see the scenario title' do |context|
15
- if context[:out].include? 'This is an empty scenario'
16
- success
17
- else
18
- failure "Output was: '#{context[:out]}'"
19
- end
20
- end
21
-
22
- end
23
-
24
- scenario :command_unit, 'Running a scenario with 1 test and 1 passing assertion' do
25
-
26
- set_up do |context|
27
- context[:scenario] = scenario 'This scenario has 1 test with 1 assertion' do
28
- when_i 'have 1 test in the scenario' do
29
- # Empty test test ;)
30
- end
31
- i_expect 'that this should pass' do
32
- success
33
- end
34
- end
35
- end
36
-
37
- when_i 'run the scenario' do |context|
38
- context[:out] = capture_stdout do context[:scenario].run end
39
- end
40
-
41
- i_expect 'to see the when_i text and the i_expect text' do |context|
42
- if context[:out].include? 'have 1 test in the scenario' and context[:out].include? 'that this should pass'
43
- success
44
- else
45
- failure
46
- end
47
- end
48
-
49
- i_expect 'to see the correct number of tests and expectations reported' do |context|
50
- if context[:out].include? '1 tests, 1 expectations with 1 successful and 0 failures'
51
- success
52
- else
53
- failure
54
- end
55
-
56
- end
5
+ Dir[File.dirname(__FILE__) + '/scenarios/*.rb'].each do |file|
6
+ require File.expand_path(file)
57
7
  end
58
8
 
59
9
  run :command_unit
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel R. Salisbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ! 'ALPHA: Test runner for one-shot command line tools. This was built
14
14
  to support writing git hooks over at http://github.com/samsalisbury/righteous-git-hooks'
@@ -20,9 +20,21 @@ files:
20
20
  - .gitignore
21
21
  - .ruby-version
22
22
  - README.md
23
+ - changelog.md
23
24
  - command-unit.gemspec
24
25
  - lib/command-unit.rb
26
+ - lib/command-unit/expectation.rb
27
+ - lib/command-unit/expectation_result.rb
28
+ - lib/command-unit/hooks
29
+ - lib/command-unit/hooks.rb
30
+ - lib/command-unit/scenario.rb
31
+ - lib/command-unit/test.rb
32
+ - lib/command-unit/totaliser.rb
33
+ - lib/string/console_colours.rb
25
34
  - test/quick-test.rb
35
+ - test/scenarios/empty_scenario.rb
36
+ - test/scenarios/one_test_one_failing_expectation.rb
37
+ - test/scenarios/one_test_one_passing_expectation.rb
26
38
  - test/test.rb
27
39
  homepage: http://github.com/samsalisbury/command-unit
28
40
  licenses: []