specdown 0.4.0.beta.1 → 0.4.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG.markdown +4 -0
  2. data/README.markdown +4 -10
  3. data/VERSION +1 -1
  4. data/features/exception_facade.feature +8 -8
  5. data/features/readme.feature +97 -0
  6. data/features/report_summary.feature +13 -13
  7. data/features/step_definitions/exception_facade.rb +1 -1
  8. data/features/step_definitions/{runner.rb → readme.rb} +2 -2
  9. data/features/step_definitions/report_summary.rb +1 -1
  10. data/features/step_definitions/reporter.rb +3 -3
  11. data/features/step_definitions/test.rb +129 -0
  12. data/features/test.feature +131 -0
  13. data/lib/specdown.rb +9 -15
  14. data/lib/specdown/command.rb +16 -11
  15. data/lib/specdown/event_handlers/command.rb +4 -0
  16. data/lib/specdown/event_handlers/readme.rb +7 -0
  17. data/lib/specdown/event_handlers/test.rb +8 -0
  18. data/lib/specdown/readme.rb +58 -0
  19. data/lib/specdown/{runner → readme}/exception_facade.rb +3 -3
  20. data/lib/specdown/readme/report_summary.rb +37 -0
  21. data/lib/specdown/readme/stats.rb +29 -0
  22. data/lib/specdown/reporter.rb +6 -6
  23. data/lib/specdown/reporters/color_terminal_reporter.rb +2 -2
  24. data/lib/specdown/reporters/terminal_reporter.rb +6 -6
  25. data/lib/specdown/reporters/text_reporter.rb +5 -5
  26. data/lib/specdown/specdown.rb +15 -4
  27. data/lib/specdown/templates/color_summary.erb +9 -11
  28. data/lib/specdown/templates/summary.erb +8 -10
  29. data/lib/specdown/test.rb +37 -0
  30. data/lib/specdown/tree.rb +0 -3
  31. metadata +40 -27
  32. data/features/runner.feature +0 -99
  33. data/lib/specdown/event_handlers/after_test.rb +0 -4
  34. data/lib/specdown/event_handlers/before_test.rb +0 -4
  35. data/lib/specdown/event_handlers/command_complete.rb +0 -4
  36. data/lib/specdown/event_handlers/run_complete.rb +0 -3
  37. data/lib/specdown/event_handlers/run_started.rb +0 -3
  38. data/lib/specdown/event_handlers/test_failed.rb +0 -3
  39. data/lib/specdown/event_handlers/test_passed.rb +0 -3
  40. data/lib/specdown/event_handlers/test_pending.rb +0 -3
  41. data/lib/specdown/event_handlers/test_undefined.rb +0 -3
  42. data/lib/specdown/hook.rb +0 -20
  43. data/lib/specdown/hooks.rb +0 -40
  44. data/lib/specdown/runner.rb +0 -61
  45. data/lib/specdown/runner/report_summary.rb +0 -37
  46. data/lib/specdown/runner/stats.rb +0 -31
@@ -0,0 +1,37 @@
1
+ module Specdown
2
+ class Test
3
+ include ::Hook
4
+ hook :execute
5
+
6
+ attr_accessor :code, :undefined_implicits
7
+ attr_reader :status, :exception, :readme
8
+
9
+ def initialize(readme=nil)
10
+ @readme = readme
11
+ @code = []
12
+ @undefined_implicits = []
13
+ end
14
+
15
+ def execute
16
+ with_hooks(:execute) do
17
+ execute_code
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def execute_code
24
+ if @undefined_implicits.empty? == false
25
+ @status = :undefined
26
+ else
27
+ begin
28
+ Specdown.sandbox.instance_eval @code.join("\n")
29
+ @status = :passing
30
+ rescue Exception => e
31
+ @status = e.class == Specdown::PendingException ? :pending : :failing
32
+ @exception = Specdown::ExceptionFacade.new e, @readme
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/specdown/tree.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  module Specdown
2
2
  class Tree
3
3
  attr_accessor :root
4
-
5
- def initialize
6
- end
7
4
  end
8
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1605695984
4
+ hash: 3272481149
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 1
12
- version: 0.4.0.beta.1
11
+ - 2
12
+ version: 0.4.0.beta.2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Parker
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-01-22 00:00:00 Z
20
+ date: 2012-01-30 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: gitdown
@@ -52,9 +52,25 @@ dependencies:
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
55
- name: cucumber
55
+ name: hook
56
56
  prerelease: false
57
57
  requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 27
63
+ segments:
64
+ - 0
65
+ - 0
66
+ - 2
67
+ version: 0.0.2
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: cucumber
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
58
74
  none: false
59
75
  requirements:
60
76
  - - ">="
@@ -64,11 +80,11 @@ dependencies:
64
80
  - 0
65
81
  version: "0"
66
82
  type: :development
67
- version_requirements: *id003
83
+ version_requirements: *id004
68
84
  - !ruby/object:Gem::Dependency
69
85
  name: rspec
70
86
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
72
88
  none: false
73
89
  requirements:
74
90
  - - ">="
@@ -78,7 +94,7 @@ dependencies:
78
94
  - 0
79
95
  version: "0"
80
96
  type: :development
81
- version_requirements: *id004
97
+ version_requirements: *id005
82
98
  description:
83
99
  email: moonmaster9000@gmail.com
84
100
  executables:
@@ -93,31 +109,23 @@ files:
93
109
  - lib/specdown/command/option_parser.rb
94
110
  - lib/specdown/command.rb
95
111
  - lib/specdown/config.rb
96
- - lib/specdown/event_handlers/after_test.rb
97
- - lib/specdown/event_handlers/before_test.rb
98
- - lib/specdown/event_handlers/command_complete.rb
99
- - lib/specdown/event_handlers/run_complete.rb
100
- - lib/specdown/event_handlers/run_started.rb
101
- - lib/specdown/event_handlers/test_failed.rb
102
- - lib/specdown/event_handlers/test_passed.rb
103
- - lib/specdown/event_handlers/test_pending.rb
104
- - lib/specdown/event_handlers/test_undefined.rb
112
+ - lib/specdown/event_handlers/command.rb
113
+ - lib/specdown/event_handlers/readme.rb
114
+ - lib/specdown/event_handlers/test.rb
105
115
  - lib/specdown/event_server.rb
106
- - lib/specdown/hook.rb
107
- - lib/specdown/hooks.rb
108
116
  - lib/specdown/implicit_parser.rb
109
117
  - lib/specdown/node.rb
110
118
  - lib/specdown/parser.rb
111
119
  - lib/specdown/pending.rb
112
120
  - lib/specdown/pending_exception.rb
121
+ - lib/specdown/readme/exception_facade.rb
122
+ - lib/specdown/readme/report_summary.rb
123
+ - lib/specdown/readme/stats.rb
124
+ - lib/specdown/readme.rb
113
125
  - lib/specdown/reporter.rb
114
126
  - lib/specdown/reporters/color_terminal_reporter.rb
115
127
  - lib/specdown/reporters/terminal_reporter.rb
116
128
  - lib/specdown/reporters/text_reporter.rb
117
- - lib/specdown/runner/exception_facade.rb
118
- - lib/specdown/runner/report_summary.rb
119
- - lib/specdown/runner/stats.rb
120
- - lib/specdown/runner.rb
121
129
  - lib/specdown/sandbox_decorators/default_assertion_library.rb
122
130
  - lib/specdown/sandbox_decorators/pending.rb
123
131
  - lib/specdown/sandbox_decorators/rspec_expectations.rb
@@ -126,6 +134,7 @@ files:
126
134
  - lib/specdown/specdown.rb
127
135
  - lib/specdown/templates/color_summary.erb
128
136
  - lib/specdown/templates/summary.erb
137
+ - lib/specdown/test.rb
129
138
  - lib/specdown/tree.rb
130
139
  - lib/specdown.rb
131
140
  - bin/specdown
@@ -144,8 +153,8 @@ files:
144
153
  - features/implicit_specs.feature
145
154
  - features/parser.feature
146
155
  - features/pending_specs.feature
156
+ - features/readme.feature
147
157
  - features/report_summary.feature
148
- - features/runner.feature
149
158
  - features/sandbox_factory.feature
150
159
  - features/specdown_examples/after_hooks/specdown/env.rb
151
160
  - features/specdown_examples/after_hooks/specdown/hooks.rb
@@ -186,13 +195,15 @@ files:
186
195
  - features/step_definitions/implicit_specs.rb
187
196
  - features/step_definitions/parser.rb
188
197
  - features/step_definitions/pending_specs.rb
198
+ - features/step_definitions/readme.rb
189
199
  - features/step_definitions/report_summary.rb
190
200
  - features/step_definitions/reporter.rb
191
201
  - features/step_definitions/reporter_factory.rb
192
- - features/step_definitions/runner.rb
193
202
  - features/step_definitions/sandbox_factory.rb
203
+ - features/step_definitions/test.rb
194
204
  - features/support/env.rb
195
205
  - features/support/hooks.rb
206
+ - features/test.feature
196
207
  homepage: http://github.com/moonmaster9000/specdown
197
208
  licenses: []
198
209
 
@@ -242,8 +253,8 @@ test_files:
242
253
  - features/implicit_specs.feature
243
254
  - features/parser.feature
244
255
  - features/pending_specs.feature
256
+ - features/readme.feature
245
257
  - features/report_summary.feature
246
- - features/runner.feature
247
258
  - features/sandbox_factory.feature
248
259
  - features/specdown_examples/after_hooks/specdown/env.rb
249
260
  - features/specdown_examples/after_hooks/specdown/hooks.rb
@@ -284,10 +295,12 @@ test_files:
284
295
  - features/step_definitions/implicit_specs.rb
285
296
  - features/step_definitions/parser.rb
286
297
  - features/step_definitions/pending_specs.rb
298
+ - features/step_definitions/readme.rb
287
299
  - features/step_definitions/report_summary.rb
288
300
  - features/step_definitions/reporter.rb
289
301
  - features/step_definitions/reporter_factory.rb
290
- - features/step_definitions/runner.rb
291
302
  - features/step_definitions/sandbox_factory.rb
303
+ - features/step_definitions/test.rb
292
304
  - features/support/env.rb
293
305
  - features/support/hooks.rb
306
+ - features/test.feature
@@ -1,99 +0,0 @@
1
- Feature: Runner
2
-
3
- The `Specdown::Runner` class accepts a markdown parse tree, and runs the tests found within.
4
-
5
- Imagine we start with this markdown file (saved at "specdown.markdown"):
6
-
7
- \# Specdown Example
8
-
9
- This is an example specdown file.
10
-
11
- \## Child Node
12
-
13
- This section is a child node. It contains some ruby code:
14
-
15
- ```ruby
16
- "simple code".should_not be(nil)
17
- ```
18
-
19
- \### First Leaf
20
-
21
- This section has a failure simulation:
22
-
23
- ```ruby
24
- raise "specdown error simulation!"
25
- ```
26
-
27
- \## Last Leaf
28
-
29
- This section is a leaf node. It contains some ruby code:
30
-
31
- ```ruby
32
- 1.should satisfy(&:odd?)
33
- ```
34
-
35
- We can generate a `Specdown::Runner` instance and run the tests in our markdown by simply passing the filename on instantiation:
36
-
37
- runner = Specdown::Runner.new "specdown.markdown"
38
- runner.run
39
-
40
- While running, it will emit events during the processing to the Specdown::EventServer. This enables all kinds of functionality, like printing the progress of the tests.
41
-
42
- We can access statistics about the run programatically:
43
-
44
- runner.stats.tests #==> 2
45
- runner.stats.failures #==> 1
46
- runner.stats.successes #==> 1
47
- runner.stats.exceptions.map(&:to_s) #==> ['StandardError: "specdown error simulation"']
48
-
49
- Scenario: Running tests
50
-
51
- Given the following specdown example file:
52
- """
53
- # Specdown Example
54
-
55
- This is an example specdown file.
56
-
57
- ## Child Node
58
-
59
- This section is a child node. It contains some ruby code:
60
-
61
- ```ruby
62
- "simple code".should_not be(nil)
63
- ```
64
-
65
- ### First Leaf
66
-
67
- This section has a failure simulation:
68
-
69
- ```ruby
70
- raise "specdown error simulation!"
71
- ```
72
-
73
- ## Last Leaf
74
-
75
- This section is a leaf node. It contains some ruby code:
76
-
77
- ```ruby
78
- 1.should satisfy(&:odd?)
79
- ```
80
- """
81
-
82
- When I generate a `Specdown::Runner` instance from it:
83
- """
84
- @runner = Specdown::Runner.new "features/fixtures/parser_example.markdown"
85
- """
86
-
87
- Then I should be able to run the tests:
88
- """
89
- @runner.run
90
- """
91
-
92
- And I should be able to access the report data programatically:
93
- """
94
- @runner.file_name.should == 'parser_example.markdown'
95
- @runner.stats.tests.should == 2
96
- @runner.stats.failures.should == 1
97
- @runner.stats.successes.should == 1
98
- @runner.stats.exceptions.map(&:exception_message).should == ["specdown error simulation!"]
99
- """
@@ -1,4 +0,0 @@
1
- Specdown::EventServer.register :after_test do |runner|
2
- Specdown::Hooks.matching_after_hooks(runner.file_name).map &:call
3
- Specdown::Hooks.matching_around_hooks(runner.file_name).map &:call
4
- end
@@ -1,4 +0,0 @@
1
- Specdown::EventServer.register :before_test do |runner|
2
- Specdown::Hooks.matching_before_hooks(runner.file_name).map &:call
3
- Specdown::Hooks.matching_around_hooks(runner.file_name).map &:call
4
- end
@@ -1,4 +0,0 @@
1
- Specdown::EventServer.register :command_complete do |results|
2
- Specdown.reporter.print_summary(results)
3
- Specdown.reporter.print_end
4
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :run_complete do |runner|
2
- Specdown.reporter.print_runner_end runner if Specdown::Config.format == :condensed
3
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :run_started do |runner|
2
- Specdown.reporter.print_runner_start runner if Specdown::Config.format == :condensed
3
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :test_failed do
2
- Specdown.reporter.print_failure nil
3
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :test_passed do
2
- Specdown.reporter.print_success nil
3
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :test_pending do
2
- Specdown.reporter.print_pending nil
3
- end
@@ -1,3 +0,0 @@
1
- Specdown::EventServer.register :test_undefined do |test|
2
- Specdown.reporter.print_undefined nil
3
- end
data/lib/specdown/hook.rb DELETED
@@ -1,20 +0,0 @@
1
- module Specdown
2
- class Hook
3
- def initialize(*filters, &callback)
4
- @filters = filters
5
- @callback = callback
6
- end
7
-
8
- def matches?(filename)
9
- return true if @filters.empty?
10
-
11
- @filters.any? do |filter|
12
- filter == filename || filter.match(filename)
13
- end
14
- end
15
-
16
- def call
17
- @callback.call
18
- end
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- module Specdown
2
- module Hooks
3
- extend self
4
-
5
- def reset!
6
- @before = []
7
- @after = []
8
- @around = []
9
- end
10
-
11
- def matching_before_hooks(filename)
12
- filter before, filename
13
- end
14
-
15
- def matching_after_hooks(filename)
16
- filter after, filename
17
- end
18
-
19
- def matching_around_hooks(filename)
20
- filter around, filename
21
- end
22
-
23
- def before
24
- @before ||= []
25
- end
26
-
27
- def after
28
- @after ||= []
29
- end
30
-
31
- def around
32
- @around ||= []
33
- end
34
-
35
- private
36
- def filter(hooks, filename)
37
- hooks.select {|hook| hook.matches? filename}
38
- end
39
- end
40
- end
@@ -1,61 +0,0 @@
1
- module Specdown
2
- class Runner
3
- attr_reader :stats, :file_path
4
-
5
- def initialize(file_path)
6
- @file_path = file_path
7
- @tree = Parser.parse File.read(file_path), Specdown::Config.implicit_specs
8
- @stats = Stats.new self
9
- end
10
-
11
- def file_name
12
- File.basename @file_path
13
- end
14
-
15
- def run
16
- EventServer.event :run_started, self
17
- depth_first_search @tree.root
18
- EventServer.event :run_complete, self
19
- self
20
- end
21
-
22
- private
23
- def depth_first_search(node, code=[], undefined_implicits=[])
24
- if node.children.empty?
25
- EventServer.event :before_test, self
26
- execute_test(code + [node.code], undefined_implicits + node.undefined_implicits)
27
- EventServer.event :after_test, self
28
- else
29
- node.children.each do |child|
30
- depth_first_search(child, (code + [node.code]), (undefined_implicits + node.undefined_implicits))
31
- end
32
- end
33
- end
34
-
35
- def execute_test(code, undefined_implicits)
36
- @stats.tests += 1
37
-
38
- if !undefined_implicits.empty?
39
- @stats.undefined_tests += 1
40
- @stats.undefined_implicits += undefined_implicits
41
- EventServer.event :test_undefined, self
42
- else
43
-
44
- begin
45
- Specdown.sandbox.instance_eval <<-CODE, file_name
46
- #{code.join("\n")}
47
- CODE
48
- EventServer.event :test_passed, self
49
-
50
- rescue Specdown::PendingException => e
51
- @stats.pending_exceptions << ExceptionFacade.new(e, self)
52
- EventServer.event :test_pending, self
53
-
54
- rescue Exception => e
55
- @stats.exceptions << ExceptionFacade.new(e, self)
56
- EventServer.event :test_failed, self
57
- end
58
- end
59
- end
60
- end
61
- end