sapphire 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,24 +4,45 @@ require 'rubygems'
4
4
  require 'sapphire'
5
5
  include Sapphire::Sapphire
6
6
 
7
- reporter = ConsoleReporter.new()
7
+ $reporters = []
8
8
 
9
9
  ARGV.each do |arg|
10
+
11
+ #if arg.start_with? "reporter="
12
+ # item = arg.split "reporter="
13
+ # $reporters << Object.const_get(item.last).new()
14
+ # next
15
+ #end
16
+
10
17
  if !arg.end_with? ".rb"
11
18
  next
12
19
  end
20
+
13
21
  require arg
14
22
  Runner.instance.last_scenario.file_name = arg if Runner.instance.last_scenario and Runner.instance.last_scenario.file_name == ""
15
23
  end
16
24
 
17
- reporter.BeginTesting
25
+ if $reporters.empty?
26
+ $reporters << ConsoleReporter.new()
27
+ end
28
+
18
29
 
19
30
  if Runner.instance.test_plans.count > 0
20
31
  Runner.instance.last_test_plan.execute
21
32
  else
33
+
34
+ Report do |x| x.BeginTesting end
35
+
22
36
  Runner.instance.scenarios.each do |scenario|
23
- scenario.execute reporter
24
- reporter.TestingComplete
25
- reporter.OutputResults
37
+ scenario.execute
26
38
  end
39
+
40
+ Report do |x| x.TestingComplete end
41
+ Report do |x| x.OutputResults end
27
42
  end
43
+
44
+ def Report(&block)
45
+ $reporters.each do |reporter|
46
+ block.call reporter
47
+ end
48
+ end
@@ -2,11 +2,11 @@ module Sapphire
2
2
  module DSL
3
3
  module TestPlans
4
4
  class FileHandler
5
- def Handle(item, reporter)
5
+ def Handle(item)
6
6
  x = AppConfig.Current.SpecsPath || ""
7
7
  require File.expand_path(x + item, __FILE__)
8
8
  Runner.instance.last_scenario.file_name = item
9
- Runner.instance.last_scenario.execute reporter
9
+ Runner.instance.last_scenario.execute
10
10
  end
11
11
  end
12
12
  end
@@ -2,12 +2,12 @@ module Sapphire
2
2
  module DSL
3
3
  module TestPlans
4
4
  class PathHandler
5
- def Handle(item, reporter)
5
+ def Handle(item)
6
6
  x = AppConfig.Current.SpecsPath || ""
7
7
  Dir[x + item + '*.rb'].each do |file|
8
8
  require file
9
9
  Runner.instance.last_scenario.file_name = file
10
- Runner.instance.last_scenario.execute reporter
10
+ Runner.instance.last_scenario.execute
11
11
  end
12
12
  end
13
13
  end
@@ -3,8 +3,7 @@ module Sapphire
3
3
  module TestPlans
4
4
 
5
5
  def TestPlan(text, &block)
6
- reporter = ConsoleReporter.new()
7
- Runner.instance.add_test_plan(TestPlan.new(text, reporter, &block))
6
+ Runner.instance.add_test_plan(TestPlan.new(text, &block))
8
7
  end
9
8
 
10
9
  class TestPlan
@@ -13,11 +12,10 @@ module Sapphire
13
12
  attr_reader :value
14
13
  attr_reader :text
15
14
 
16
- def initialize(text, reporter, &block)
15
+ def initialize(text, &block)
17
16
  @value = text
18
17
  @text = text.to_s
19
18
  @block = block
20
- @reporter = reporter
21
19
 
22
20
  @items = []
23
21
  @handlers = []
@@ -36,7 +34,7 @@ module Sapphire
36
34
  @handlers.each do |handler|
37
35
  handler.keys.each do |handler_key|
38
36
  if(handler_key == key)
39
- handler[handler_key].Handle item[key], @reporter
37
+ handler[handler_key].Handle item[key]
40
38
  end
41
39
  end
42
40
  end
@@ -48,11 +46,17 @@ module Sapphire
48
46
  end
49
47
 
50
48
  def execute
51
- @reporter.BeginTesting
49
+ Report do |x| x.BeginTesting end
52
50
  $stdout.puts ""
53
51
  @block.call
54
- @reporter.TestingComplete
55
- @reporter.OutputResults
52
+ Report do |x| x.TestingComplete end
53
+ Report do |x| x.OutputResults end
54
+ end
55
+
56
+ def Report(&block)
57
+ $reporters.each do |reporter|
58
+ block.call reporter
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -8,19 +8,20 @@ module Sapphire
8
8
  @failing_count = 0
9
9
  @pending_count = 0
10
10
  @test_count = 0
11
+ @output = $stdout
11
12
  end
12
13
 
13
14
  def ScenarioStart(scenario)
14
- $stdout.puts scenario.file_name + ": "
15
+ @output.puts scenario.file_name + ": "
15
16
  end
16
17
 
17
18
  def ScenarioComplete(scenario)
18
- $stdout.puts ""
19
+ @output.puts ""
19
20
  end
20
21
 
21
22
  def Indent(depth)
22
23
  (1..depth).each do
23
- $stdout.print "\t"
24
+ @output.print "\t"
24
25
  end
25
26
  end
26
27
 
@@ -28,28 +29,28 @@ module Sapphire
28
29
  Indent(depth)
29
30
 
30
31
  if result.type == 'pass'
31
- $stdout.puts result.text.colorize :green
32
+ @output.puts result.text.colorize :green
32
33
  elsif result.type == 'pending'
33
- $stdout.puts result.text.colorize :yellow
34
+ @output.puts result.text.colorize :yellow
34
35
  Indent(depth+1)
35
- $stdout.puts " ## Not Yet Implemented ##"
36
+ @output.puts " ## Not Yet Implemented ##"
36
37
  else
37
- $stdout.puts result.text.colorize :red
38
+ @output.puts result.text.colorize :red
38
39
  if result.messages.is_a? Array
39
40
  result.messages.each do |message|
40
41
  Indent(depth+1)
41
- $stdout.puts message
42
+ @output.puts message
42
43
  end
43
44
 
44
45
  else
45
46
  Indent(depth+1)
46
- $stdout.puts result.messages
47
+ @output.puts result.messages
47
48
  end
48
- $stdout.puts ""
49
+ @output.puts ""
49
50
  result.stack.each do |line|
50
51
  #if (!line.include? "sapphire")
51
52
  Indent(depth+1)
52
- $stdout.puts line
53
+ @output.puts line
53
54
  #end
54
55
  end
55
56
 
@@ -57,7 +58,7 @@ module Sapphire
57
58
  end
58
59
 
59
60
  def InsertLineBreak()
60
- $stdout.puts ""
61
+ @output.puts ""
61
62
  end
62
63
 
63
64
  def TestStarted(test)
@@ -66,19 +67,19 @@ module Sapphire
66
67
 
67
68
  def TestPassed(test)
68
69
  @passing_count = @passing_count + 1
69
- $stdout.print ".".colorize :green
70
+ @output.print ".".colorize :green
70
71
  end
71
72
 
72
73
  def TestFailed(test)
73
74
  @failing_count = @failing_count + 1
74
75
  Add test
75
- $stdout.print "F".colorize :red
76
+ @output.print "F".colorize :red
76
77
  end
77
78
 
78
79
  def TestPending(test)
79
80
  @pending_count = @pending_count + 1
80
81
  Add test
81
- $stdout.print "*".colorize :yellow
82
+ @output.print "*".colorize :yellow
82
83
  end
83
84
 
84
85
  def Add(r)
@@ -99,18 +100,18 @@ module Sapphire
99
100
  end
100
101
 
101
102
  def OutputResults()
102
- $stdout.puts ""
103
+ @output.puts ""
103
104
 
104
105
  @not_passing.keys.each do |key|
105
106
  self.PrintResult @not_passing[key]
106
107
  end
107
108
 
108
- $stdout.puts ""
109
- $stdout.puts "Finished in " + (@end - @start).round().to_s + " seconds."
110
- $stdout.puts "Test Count: " + @test_count.to_s
111
- $stdout.puts "Passing: " + @passing_count.to_s.colorize(:green)
112
- $stdout.puts "Failing: " + @failing_count.to_s.colorize(:red)
113
- $stdout.puts "Pending: " + @pending_count.to_s.colorize(:yellow)
109
+ @output.puts ""
110
+ @output.puts "Finished in " + (@end - @start).round().to_s + " seconds."
111
+ @output.puts "Test Count: " + @test_count.to_s
112
+ @output.puts "Passing: " + @passing_count.to_s.colorize(:green)
113
+ @output.puts "Failing: " + @failing_count.to_s.colorize(:red)
114
+ @output.puts "Pending: " + @pending_count.to_s.colorize(:yellow)
114
115
  end
115
116
 
116
117
  def Output(result, depth)
@@ -14,7 +14,7 @@ module Sapphire
14
14
 
15
15
  def initialize(token)
16
16
  @token = token
17
- @behaviors = []
17
+ @requirements = []
18
18
  end
19
19
 
20
20
  def AddRequirement(requirement)
@@ -1,27 +1,33 @@
1
1
  module Sapphire
2
2
  module Testing
3
3
  module Executable
4
- def execute(reporter)
4
+ def execute()
5
5
  start = Time.now
6
- reporter.TestStarted(self)
6
+ Report do |x| x.TestStarted(self) end
7
7
  begin
8
8
  if(self.value.is_a? Pending)
9
9
  result = ResultTree.new(self.text, TestResult.new("pending", self, "Pending", "", Time.now - start))
10
10
  self.AddResult(result)
11
- reporter.TestPending result
11
+ Report do |x| x.TestPending(result) end
12
12
  return
13
13
  end
14
14
  self.block.call
15
15
  result = ResultTree.new(self.text, TestResult.new("pass", self, "Success", "", Time.now - start))
16
16
  self.AddResult(result)
17
- reporter.TestPassed result
17
+ Report do |x| x.TestPassed(result) end
18
18
  rescue => msg
19
19
  stack = msg.backtrace
20
20
  message = msg.messages if (msg.is_a? ExpectationException)
21
21
  message ||= msg.message
22
22
  result = ResultTree.new(self.text, TestResult.new("fail", self, message, stack, Time.now - start))
23
23
  self.AddResult(result)
24
- reporter.TestFailed result
24
+ Report do |x| x.TestFailed(result) end
25
+ end
26
+ end
27
+
28
+ def Report(&block)
29
+ $reporters.each do |reporter|
30
+ block.call reporter
25
31
  end
26
32
  end
27
33
  end
@@ -9,6 +9,7 @@ module Sapphire
9
9
  @failing_count = 0
10
10
  @pending_count = 0
11
11
  @test_count = 0
12
+ @output = $stdout
12
13
  end
13
14
 
14
15
  def TestStarted(test)
@@ -17,44 +18,44 @@ module Sapphire
17
18
 
18
19
  def TestPassed(test)
19
20
  @passing_count = @passing_count + 1
20
- $stdout.puts " <dd class=\"spec passed\"><span class=\"passed_spec_name\">#{test.text}</span></dd>"
21
+ @output.puts " <dd class=\"spec passed\"><span class=\"passed_spec_name\">#{test.text}</span></dd>"
21
22
  end
22
23
 
23
24
  def TestFailed(test)
24
25
 
25
26
  failure_style = 'failed'
26
- $stdout.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
27
+ @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
27
28
  @header_red = true
28
- $stdout.puts " <script type=\"text/javascript\">makeRed('example_group_#{@example_group_number}');</script>" unless @example_group_red
29
+ @output.puts " <script type=\"text/javascript\">makeRed('example_group_#{@example_group_number}');</script>" unless @example_group_red
29
30
  @example_group_red = true
30
- $stdout.puts " <dd class=\"spec #{failure_style}\">"
31
- $stdout.puts " <span class=\"failed_spec_name\">#{test.text}</span>"
32
- $stdout.puts " <div class=\"failure\" id=\"failure_#{@test_count}\">"
31
+ @output.puts " <dd class=\"spec #{failure_style}\">"
32
+ @output.puts " <span class=\"failed_spec_name\">#{test.text}</span>"
33
+ @output.puts " <div class=\"failure\" id=\"failure_#{@test_count}\">"
33
34
 
34
35
  if test.messages.is_a? Array
35
36
  message_block = ""
36
37
  test.messages.each do |message|
37
38
  message_block += message + "<br>"
38
39
  end
39
- $stdout.puts " <div class=\"message\"><pre>#{message_block}</pre></div>"
40
+ @output.puts " <div class=\"message\"><pre>#{message_block}</pre></div>"
40
41
  else
41
- $stdout.puts " <div class=\"message\"><pre>#{test.messages}</pre></div>"
42
+ @output.puts " <div class=\"message\"><pre>#{test.messages}</pre></div>"
42
43
  end
43
44
 
44
45
  test.stack.each do |line|
45
46
  if (!line.include? "sapphire")
46
- $stdout.puts " <div class=\"backtrace\"><pre>#{line}</pre></div>"
47
+ @output.puts " <div class=\"backtrace\"><pre>#{line}</pre></div>"
47
48
  end
48
49
  end
49
50
 
50
- $stdout.puts " </div>"
51
- $stdout.puts " </dd>"
51
+ @output.puts " </div>"
52
+ @output.puts " </dd>"
52
53
  end
53
54
 
54
55
  def TestPending(test)
55
- $stdout.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
56
- $stdout.puts " <script type=\"text/javascript\">makeYellow('example_group_#{@example_group_number}');</script>" unless @example_group_red
57
- $stdout.puts " <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{test.text} (PENDING: ### Not Yet Implemented ###)</span></dd>"
56
+ @output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
57
+ @output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{@example_group_number}');</script>" unless @example_group_red
58
+ @output.puts " <dd class=\"spec not_implemented\"><span class=\"not_implemented_spec_name\">#{test.text} (PENDING: ### Not Yet Implemented ###)</span></dd>"
58
59
  end
59
60
 
60
61
  def TestingComplete
@@ -63,30 +64,30 @@ module Sapphire
63
64
  totals = "#{@test_count} example#{'s' unless @test_count == 1}, #{@failure_count} failure#{'s' unless @failure_count == 1}"
64
65
  totals << ", #{@pending_count} pending" if @pending_count > 0
65
66
 
66
- $stdout.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{(@end - @start).round(2).to_s} seconds</strong>\";</script>"
67
- $stdout.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
68
- $stdout.puts "</div>"
69
- $stdout.puts "</div>"
70
- $stdout.puts "</body>"
71
- $stdout.puts "</html>"
67
+ @output.puts "<script type=\"text/javascript\">document.getElementById('duration').innerHTML = \"Finished in <strong>#{(@end - @start).round(2).to_s} seconds</strong>\";</script>"
68
+ @output.puts "<script type=\"text/javascript\">document.getElementById('totals').innerHTML = \"#{totals}\";</script>"
69
+ @output.puts "</div>"
70
+ @output.puts "</div>"
71
+ @output.puts "</body>"
72
+ @output.puts "</html>"
72
73
  end
73
74
 
74
75
  def BeginTesting
75
76
  @start = Time.now
76
- $stdout.puts html_header
77
- $stdout.puts report_header
77
+ @output.puts html_header
78
+ @output.puts report_header
78
79
  end
79
80
 
80
81
  def ScenarioStart(scenario)
81
82
  @example_group_red = false
82
83
  @example_group_number += 1
83
84
  unless @example_group_number == 1
84
- $stdout.puts " </dl>"
85
- $stdout.puts "</div>"
85
+ @output.puts " </dl>"
86
+ @output.puts "</div>"
86
87
  end
87
- $stdout.puts "<div class=\"example_group\">"
88
- $stdout.puts " <dl>"
89
- $stdout.puts " <dt id=\"example_group_#{@example_group_number}\">#{scenario.text}</dt>"
88
+ @output.puts "<div class=\"example_group\">"
89
+ @output.puts " <dl>"
90
+ @output.puts " <dt id=\"example_group_#{@example_group_number}\">#{scenario.text}</dt>"
90
91
  end
91
92
 
92
93
  def OutputResults()
@@ -2,16 +2,22 @@ module Sapphire
2
2
  module Testing
3
3
  module TestRunnerAdapter
4
4
 
5
- def execute(reporter)
6
- reporter.ScenarioStart self
5
+ def Report(&block)
6
+ $reporters.each do |reporter|
7
+ block.call reporter
8
+ end
9
+ end
10
+
11
+ def execute()
12
+ Report do |x| x.ScenarioStart(self) end
7
13
 
8
14
  self.backgrounds.each do |b|
9
15
 
10
- b.execute reporter
16
+ b.execute
11
17
 
12
18
  b.and.each do |g_a|
13
19
 
14
- g_a.execute reporter
20
+ g_a.execute
15
21
 
16
22
  end
17
23
 
@@ -20,29 +26,29 @@ module Sapphire
20
26
  self.givens.each do |g|
21
27
  g.when.each do |w|
22
28
 
23
- g.execute reporter
29
+ g.execute
24
30
 
25
31
  g.and.each do |g_a|
26
32
 
27
- g_a.execute reporter
33
+ g_a.execute
28
34
 
29
35
  end
30
36
 
31
- w.execute reporter
37
+ w.execute
32
38
 
33
39
  w.and.each do |w_a|
34
40
 
35
- w_a.execute reporter
41
+ w_a.execute
36
42
 
37
43
  end
38
44
 
39
45
  w.then.each do |t|
40
46
 
41
- t.execute reporter
47
+ t.execute
42
48
 
43
49
  t.and.each do |t_a|
44
50
 
45
- t_a.execute reporter
51
+ t_a.execute
46
52
 
47
53
  end
48
54
 
@@ -52,13 +58,13 @@ module Sapphire
52
58
 
53
59
  if(g.finally)
54
60
 
55
- g.finally.execute reporter
61
+ g.finally.execute
56
62
 
57
63
  end
58
64
 
59
65
  end
60
66
 
61
- reporter.ScenarioComplete self
67
+ Report do |x| x.ScenarioComplete(self) end
62
68
 
63
69
  end
64
70
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapphire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &10000008 !ruby/object:Gem::Requirement
16
+ requirement: &10056984 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10000008
24
+ version_requirements: *10056984
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &9999756 !ruby/object:Gem::Requirement
27
+ requirement: &10056732 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9999756
35
+ version_requirements: *10056732
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Platform
38
- requirement: &9999504 !ruby/object:Gem::Requirement
38
+ requirement: &10056480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9999504
46
+ version_requirements: *10056480
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email: