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
data/lib/specdown.rb CHANGED
@@ -2,34 +2,28 @@ require 'kramdown'
2
2
  require 'term/ansicolor'
3
3
  require 'erb'
4
4
  require 'optparse'
5
+ require 'hook'
5
6
  require 'specdown/parser'
6
7
  require 'specdown/implicit_parser'
7
8
  require 'specdown/node'
8
9
  require 'specdown/tree'
9
- require 'specdown/runner'
10
+ require 'specdown/readme'
10
11
  require 'specdown/reporter'
11
- require 'specdown/runner/stats'
12
+ require 'specdown/test'
13
+ require 'specdown/readme/stats'
12
14
  require 'specdown/command'
13
15
  require 'specdown/event_server'
14
- require 'specdown/event_handlers/before_test'
15
- require 'specdown/event_handlers/after_test'
16
- require 'specdown/event_handlers/command_complete'
17
- require 'specdown/event_handlers/run_complete'
18
- require 'specdown/event_handlers/run_started'
19
- require 'specdown/event_handlers/test_failed'
20
- require 'specdown/event_handlers/test_passed'
21
- require 'specdown/event_handlers/test_pending'
22
- require 'specdown/event_handlers/test_undefined'
16
+ require 'specdown/event_handlers/test'
17
+ require 'specdown/event_handlers/command'
18
+ require 'specdown/event_handlers/readme'
23
19
  require 'specdown/pending'
24
20
  require 'specdown/pending_exception'
25
21
  require 'specdown/config'
26
22
  require 'specdown/specdown'
27
23
  require 'specdown/sandbox_factory'
28
- require 'specdown/hooks'
29
- require 'specdown/hook'
30
24
  require 'specdown/command/option_parser'
31
- require 'specdown/runner/report_summary'
32
- require 'specdown/runner/exception_facade'
25
+ require 'specdown/readme/report_summary'
26
+ require 'specdown/readme/exception_facade'
33
27
  require 'specdown/reporters/terminal_reporter'
34
28
  require 'specdown/reporters/color_terminal_reporter'
35
29
  require 'specdown/reporters/text_reporter'
@@ -1,9 +1,20 @@
1
1
  module Specdown
2
2
  class Command
3
+ include ::Hook
4
+ hook :execute
5
+
6
+ attr_reader :readmes
7
+
8
+ def initialize
9
+ @readmes = []
10
+ end
11
+
3
12
  def execute
4
- load_test_environment
5
- parse_options
6
- run
13
+ with_hooks :execute do
14
+ load_test_environment
15
+ parse_options
16
+ run
17
+ end
7
18
  end
8
19
 
9
20
  private
@@ -18,15 +29,9 @@ module Specdown
18
29
  end
19
30
 
20
31
  def run
21
- @results = []
22
-
23
- Kernel.at_exit do
24
- Specdown::EventServer.event :command_complete, @results
25
- end
26
-
27
32
  Specdown::Config.tests.each do |markdown|
28
- @results << Runner.new(markdown)
29
- @results.last.run
33
+ @readmes << Specdown::Readme.new(markdown)
34
+ @readmes.last.execute
30
35
  end
31
36
  end
32
37
  end
@@ -0,0 +1,4 @@
1
+ Specdown::Command.after_execute do |command|
2
+ Specdown.reporter.print_summary command.readmes
3
+ Specdown.reporter.print_end
4
+ end
@@ -0,0 +1,7 @@
1
+ Specdown::Readme.before_execute do |readme|
2
+ Specdown.reporter.print_readme_start readme if Specdown::Config.format == :condensed
3
+ end
4
+
5
+ Specdown::Readme.after_execute do |readme|
6
+ Specdown.reporter.print_readme_end readme if Specdown::Config.format == :condensed
7
+ end
@@ -0,0 +1,8 @@
1
+ Specdown::Test.after_execute do |test|
2
+ case test.status
3
+ when :passing then Specdown.reporter.print_success test
4
+ when :failing then Specdown.reporter.print_failure test
5
+ when :undefined then Specdown.reporter.print_undefined test
6
+ when :pending then Specdown.reporter.print_pending test
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ module Specdown
2
+ class Readme
3
+ include ::Hook
4
+ hook :execute
5
+
6
+ attr_reader :tests, :stats, :file_path
7
+
8
+ def initialize(file_path)
9
+ @file_path = file_path
10
+ @tests = []
11
+ @stats = Stats.new self
12
+ build_tests
13
+ end
14
+
15
+ def exceptions
16
+ @tests.collect(&:exception).compact
17
+ end
18
+
19
+ def pending_exceptions
20
+ exceptions.select {|e| e.exception_class == Specdown::PendingException }
21
+ end
22
+
23
+ def undefined_implicits
24
+ @tests.collect(&:undefined_implicits).flatten
25
+ end
26
+
27
+ def file_name
28
+ File.basename @file_path
29
+ end
30
+
31
+ def execute
32
+ with_hooks :execute do
33
+ @tests.map &:execute
34
+ end
35
+
36
+ self
37
+ end
38
+
39
+ private
40
+ def build_tests
41
+ tree = Parser.parse File.read(file_path), Specdown::Config.implicit_specs
42
+ depth_first_search(tree.root)
43
+ end
44
+
45
+ def depth_first_search(node, code=[], undefined_implicits=[])
46
+ if node.children.empty?
47
+ test = Specdown::Test.new self
48
+ test.code = code + [node.code]
49
+ test.undefined_implicits = undefined_implicits + node.undefined_implicits
50
+ @tests << test
51
+ else
52
+ node.children.each do |child|
53
+ depth_first_search(child, code + [node.code], undefined_implicits + node.undefined_implicits)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,8 +1,8 @@
1
1
  module Specdown
2
2
  class ExceptionFacade
3
- def initialize(exception, runner)
3
+ def initialize(exception, readme)
4
4
  @exception = exception
5
- @runner = runner
5
+ @readme = readme
6
6
  end
7
7
 
8
8
  def exception_class
@@ -18,7 +18,7 @@ module Specdown
18
18
  end
19
19
 
20
20
  def test_filename
21
- @runner.file_name
21
+ @readme.file_name
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,37 @@
1
+ module Specdown
2
+ class ReportSummary
3
+ attr_reader :readmes
4
+
5
+ def initialize(readmes)
6
+ @readmes = readmes.respond_to?(:map) ? readmes : [readmes]
7
+ end
8
+
9
+ def num_markdowns
10
+ @num_markdowns ||= @readmes.count
11
+ end
12
+
13
+ def num_tests
14
+ @num_tests ||= @readmes.map(&:stats).map(&:num_tests).inject(0, &:+)
15
+ end
16
+
17
+ def num_pending
18
+ @num_pending ||= @readmes.map(&:stats).map(&:num_pending).inject(0, &:+)
19
+ end
20
+
21
+ def num_undefined
22
+ @num_undefined ||= @readmes.map(&:stats).map(&:num_undefined).inject(0, &:+)
23
+ end
24
+
25
+ def num_failing
26
+ @num_failing ||= @readmes.map(&:stats).map(&:num_failing).inject(0, &:+)
27
+ end
28
+
29
+ def num_passing
30
+ @num_passing ||= @readmes.map(&:stats).map(&:num_passing).inject(0, &:+)
31
+ end
32
+
33
+ def exceptions
34
+ @exceptions ||= @readmes.map(&:tests).flatten.map(&:exception).compact
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module Specdown
2
+ class Stats
3
+ attr_reader :readme
4
+
5
+ def initialize(readme=nil)
6
+ @readme = readme
7
+ end
8
+
9
+ def num_tests
10
+ @readme.tests.count
11
+ end
12
+
13
+ def num_passing
14
+ @readme.tests.select {|test| test.status == :passing}.count
15
+ end
16
+
17
+ def num_failing
18
+ @readme.tests.select {|test| test.status == :failing}.count
19
+ end
20
+
21
+ def num_pending
22
+ @readme.tests.select {|test| test.status == :pending}.count
23
+ end
24
+
25
+ def num_undefined
26
+ @readme.tests.select {|test| test.status == :undefined}.count
27
+ end
28
+ end
29
+ end
@@ -1,22 +1,22 @@
1
1
  module Specdown
2
2
  module Reporter
3
- def summary(runners)
4
- ReportSummary.new(runners)
3
+ def summary(readmes)
4
+ ReportSummary.new(readmes)
5
5
  end
6
6
 
7
7
  def print_start
8
8
  raise NotImplementedError
9
9
  end
10
10
 
11
- def print_runner_start(runner)
11
+ def print_readme_start(readme)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
15
- def print_runner_summary(runner)
15
+ def print_readme_summary(readme)
16
16
  raise NotImplementedError
17
17
  end
18
18
 
19
- def print_runner_end(runner)
19
+ def print_readme_end(readme)
20
20
  raise NotImplementedError
21
21
  end
22
22
 
@@ -28,7 +28,7 @@ module Specdown
28
28
  raise NotImplementedError
29
29
  end
30
30
 
31
- def print_summary(runners)
31
+ def print_summary(readmes)
32
32
  raise NotImplementedError
33
33
  end
34
34
 
@@ -16,8 +16,8 @@ module Specdown
16
16
  Term::ANSIColor.yellow super
17
17
  end
18
18
 
19
- def print_runner_start(runner)
20
- print Term::ANSIColor.bold("#{runner.file_name}: ")
19
+ def print_readme_start(readme)
20
+ print Term::ANSIColor.bold("#{readme.file_name}: ")
21
21
  end
22
22
 
23
23
  private
@@ -24,14 +24,14 @@ module Specdown
24
24
  def print_end
25
25
  end
26
26
 
27
- def print_runner_start(runner)
28
- print "#{runner.file_name}: "
27
+ def print_readme_start(readme)
28
+ print "#{readme.file_name}: "
29
29
  end
30
30
 
31
- def print_runner_summary(runner)
31
+ def print_readme_summary(readme)
32
32
  end
33
33
 
34
- def print_runner_end(runner)
34
+ def print_readme_end(readme)
35
35
  print "\n"
36
36
  end
37
37
 
@@ -57,8 +57,8 @@ module Specdown
57
57
  print undefined
58
58
  end
59
59
 
60
- def print_summary(runners)
61
- @report_summary = summary(runners)
60
+ def print_summary(readmes)
61
+ @report_summary = summary(readmes)
62
62
  bounding = binding rescue proc {}
63
63
  template.run bounding
64
64
  end
@@ -11,11 +11,11 @@ module Specdown
11
11
  @file.write "\n\n"
12
12
  end
13
13
 
14
- def print_runner_start(runner)
15
- @file.write(runner.file_name + ": ")
14
+ def print_readme_start(readme)
15
+ @file.write(readme.file_name + ": ")
16
16
  end
17
17
 
18
- def print_runner_end(runner)
18
+ def print_readme_end(readme)
19
19
  @file.write "\n\n"
20
20
  end
21
21
 
@@ -39,8 +39,8 @@ module Specdown
39
39
  @file.close
40
40
  end
41
41
 
42
- def print_summary(runners)
43
- @report_summary = summary(runners)
42
+ def print_summary(readmes)
43
+ @report_summary = summary(readmes)
44
44
  bounding = binding rescue proc {}
45
45
  @file.write template.result(bounding)
46
46
  end
@@ -3,7 +3,6 @@ module Specdown
3
3
 
4
4
  def reset!
5
5
  Config.reset!
6
- Hooks.reset!
7
6
  end
8
7
 
9
8
  def sandbox
@@ -15,14 +14,26 @@ module Specdown
15
14
  end
16
15
 
17
16
  def before(*filters, &callback)
18
- Hooks.before << Hook.new(*filters, &callback)
17
+ Specdown::Test.before_execute do |test|
18
+ if filters.empty? || filters.any? {|filter| filter.match test.readme.file_name}
19
+ callback.call
20
+ end
21
+ end
19
22
  end
20
23
 
21
24
  def after(*filters, &callback)
22
- Hooks.after << Hook.new(*filters, &callback)
25
+ Specdown::Test.after_execute do |test|
26
+ if filters.empty? || filters.any? {|filter| filter.match test.readme.file_name}
27
+ callback.call
28
+ end
29
+ end
23
30
  end
24
31
 
25
32
  def around(*filters, &callback)
26
- Hooks.around << Hook.new(*filters, &callback)
33
+ Specdown::Test.around_execute do |test|
34
+ if filters.empty? || filters.any? {|filter| filter.match test.readme.file_name}
35
+ callback.call
36
+ end
37
+ end
27
38
  end
28
39
  end
@@ -1,27 +1,25 @@
1
1
 
2
2
 
3
3
  ---------------------------------------------------------------------------
4
- <%= Term::ANSIColor.bold format_stat("markdown", @report_summary.num_markdowns) %>
5
- <%= Term::ANSIColor.bold format_stat("test", @report_summary.num_tests) %>
6
- <%= Term::ANSIColor.cyan format_stat("pending test", @report_summary.num_pendings) %>
7
- <%= Term::ANSIColor.green format_stat("success", @report_summary.num_successes) %>
8
- <%= Term::ANSIColor.red format_stat("failure", @report_summary.num_failures) %>
9
- <%= Term::ANSIColor.yellow(@report_summary.num_undefined.to_s + " undefined") %>
4
+ <%= Term::ANSIColor.bold format_stat("markdown", @report_summary.num_markdowns) %>
5
+ <%= Term::ANSIColor.bold format_stat("test", @report_summary.num_tests) %>
6
+ <%= Term::ANSIColor.cyan format_stat("pending test", @report_summary.num_pending) %>
7
+ <%= Term::ANSIColor.green format_stat("success", @report_summary.num_passing) %>
8
+ <%= Term::ANSIColor.red format_stat("failure", @report_summary.num_failing) %>
9
+ <%= Term::ANSIColor.yellow(@report_summary.num_undefined.to_s + " undefined") %>
10
10
  ---------------------------------------------------------------------------
11
- <% runners.map(&:stats).each do |stat| %>
12
- <% stat.exceptions.each do |e| %>
11
+ <% readmes.collect(&:exceptions).flatten.each do |e| %>
13
12
  <%= Term::ANSIColor.bold(Term::ANSIColor.cyan "In #{e.test_filename}") %>: <%= Term::ANSIColor.bold(Term::ANSIColor.red "#<#{e.exception_class}>:") %> <%=e.exception_message%>
14
13
  <%= Term::ANSIColor.red e.exception_backtrace.join("\n") %>
15
14
  <% end %>
16
- <% end %>
17
- <% runners.collect(&:stats).collect(&:pending_exceptions).flatten.each do |pending_exception| %>
15
+ <% readmes.collect(&:pending_exceptions).flatten.each do |pending_exception| %>
18
16
  <%= Term::ANSIColor.bold(Term::ANSIColor.cyan "In #{pending_exception.test_filename}") %>: <%= Term::ANSIColor.bold(Term::ANSIColor.red "#<#{pending_exception.exception_class}>:") %> <%=pending_exception.exception_message%>
19
17
  <%= Term::ANSIColor.red pending_exception.exception_backtrace.join("\n") %>
20
18
  <% end %>
21
19
  <% if @report_summary.num_undefined > 0 %>
22
20
  <%= Term::ANSIColor.yellow 'Now add the following implicit spec definition to a file suffixed with ".specdown":'%>
23
21
  <% end %>
24
- <% runners.collect(&:stats).collect(&:undefined_implicits).flatten.each do |implicit_key| %>
22
+ <% readmes.collect(&:undefined_implicits).flatten.each do |implicit_key| %>
25
23
  <%= Term::ANSIColor.yellow implicit_key %>
26
24
  <%= Term::ANSIColor.yellow("-" * implicit_key.length) %>
27
25
 
@@ -1,27 +1,25 @@
1
1
 
2
2
 
3
3
  ---------------------------------------------------------------------------
4
- <%= format_stat("markdown", @report_summary.num_markdowns) %>
5
- <%= format_stat("test", @report_summary.num_tests) %>
6
- <%= format_stat("pending test", @report_summary.num_pendings)%>
7
- <%= format_stat("success", @report_summary.num_successes) %>
8
- <%= format_stat("failure", @report_summary.num_failures) %>
4
+ <%= format_stat("markdown", @report_summary.num_markdowns) %>
5
+ <%= format_stat("test", @report_summary.num_tests) %>
6
+ <%= format_stat("pending test", @report_summary.num_pending) %>
7
+ <%= format_stat("success", @report_summary.num_passing) %>
8
+ <%= format_stat("failure", @report_summary.num_failing) %>
9
9
  <%= @report_summary.num_undefined %> undefined
10
10
  ---------------------------------------------------------------------------
11
- <% runners.map(&:stats).each do |stat| %>
12
- <% stat.exceptions.each do |e| %>
11
+ <% readmes.collect(&:exceptions).flatten.each do |e| %>
13
12
  In <%=e.test_filename%>: <#<%=e.exception_class%>> <%=e.exception_message%>
14
13
  <%= e.exception_backtrace.join "\n" %>
15
14
  <% end %>
16
- <% stat.pending_exceptions.each do |e| %>
15
+ <% readmes.collect(&:pending_exceptions).flatten.each do |e| %>
17
16
  In <%=e.test_filename%>: <#<%=e.exception_class%>> <%=e.exception_message%>
18
17
  <%= e.exception_backtrace.join "\n" %>
19
18
  <% end %>
20
- <% end %>
21
19
  <% if @report_summary.num_undefined > 0 %>
22
20
  Now add the following implicit spec definition to a file suffixed with ".specdown":
23
21
  <% end %>
24
- <% runners.collect(&:stats).collect(&:undefined_implicits).flatten.each do |implicit_key| %>
22
+ <% readmes.collect(&:undefined_implicits).flatten.each do |implicit_key| %>
25
23
  <%= implicit_key %>
26
24
  <%= "-" * implicit_key.length %>
27
25