sapphire 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,26 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
2
 
3
3
  require 'sapphire'
4
-
5
4
  include Sapphire::Sapphire
6
5
 
6
+ reporter = ConsoleReporter.new()
7
+
7
8
  ARGV.each do |arg|
9
+ if !arg.end_with? ".rb"
10
+ next
11
+ end
8
12
  require arg
9
- Runner.instance.last_scenario.execute 1
13
+ Runner.instance.last_scenario.file_name = arg
14
+ end
15
+
16
+ if Runner.instance.test_plans.count > 0
17
+ Runner.instance.last_test_plan.execute reporter
18
+ else
19
+ Runner.instance.scenarios.each do |scenario|
20
+ scenario.execute reporter
21
+ end
10
22
  end
11
23
 
12
- ConsoleReporter.new().OutputResults
24
+
25
+
26
+ reporter.OutputResults
@@ -1,5 +1,4 @@
1
1
  require "rubygems"
2
- require "rspec"
3
2
  require 'yaml'
4
3
  require 'selenium-webdriver'
5
4
  require 'delegate'
@@ -18,7 +18,17 @@ module Sapphire
18
18
  end
19
19
 
20
20
  def Evaluate(evaluation)
21
- evaluation.left.should_not == evaluation.right
21
+ if(evaluation.left == evaluation.right)
22
+ messages = []
23
+
24
+ messages << "expected NOT: (nil)" if evaluation.left == nil
25
+ messages << "expected NOT: " + evaluation.left.to_s if evaluation.left != nil
26
+ messages << "got: (nil)" if evaluation.right == nil
27
+ messages << "got: " + evaluation.right.to_s if evaluation.right != nil
28
+
29
+ raise ExpectationException.new(messages)
30
+ end
31
+ #evaluation.left.should_not == evaluation.right
22
32
  end
23
33
 
24
34
  def execute
@@ -21,7 +21,16 @@ module Sapphire
21
21
  end
22
22
 
23
23
  if(results.is_a? Evaluation)
24
- results.left.should == results.right
24
+ if(results.left != results.right)
25
+ messages = []
26
+
27
+ messages << "expected: (nil)" if results.left == nil
28
+ messages << "expected: " + results.left.to_s if results.left != nil
29
+ messages << "got: (nil)" if results.right == nil
30
+ messages << "got: " + results.right.to_s if results.right != nil
31
+
32
+ raise ExpectationException.new(messages)
33
+ end
25
34
  return
26
35
  end
27
36
 
@@ -10,6 +10,7 @@ module Sapphire
10
10
  attr_reader :givens
11
11
  attr_reader :backgrounds
12
12
  attr_reader :result
13
+ attr_accessor :file_name
13
14
 
14
15
  def initialize(text, &block)
15
16
  @value = text
@@ -2,12 +2,11 @@ module Sapphire
2
2
  module DSL
3
3
  module TestPlans
4
4
  class FileHandler
5
- def Handle(item)
5
+ def Handle(item, reporter)
6
6
  x = AppConfig.Current.SpecsPath || ""
7
7
  require File.expand_path(x + item, __FILE__)
8
- $stdout.puts item + ": "
9
- Runner.instance.last_scenario.execute 1
10
- $stdout.puts ""
8
+ Runner.instance.last_scenario.file_name = item
9
+ Runner.instance.last_scenario.execute reporter
11
10
  end
12
11
  end
13
12
  end
@@ -2,13 +2,12 @@ module Sapphire
2
2
  module DSL
3
3
  module TestPlans
4
4
  class PathHandler
5
- def Handle(item)
5
+ def Handle(item, reporter)
6
6
  x = AppConfig.Current.SpecsPath || ""
7
7
  Dir[x + item + '*.rb'].each do |file|
8
8
  require file
9
- $stdout.puts file + ": "
10
- Runner.instance.last_scenario.execute 1
11
- $stdout.puts ""
9
+ Runner.instance.last_scenario.file_name = file
10
+ Runner.instance.last_scenario.execute reporter
12
11
  end
13
12
  end
14
13
  end
@@ -3,8 +3,9 @@ module Sapphire
3
3
  module TestPlans
4
4
 
5
5
  def TestPlan(text, &block)
6
- Runner.instance.add_test_plan(TestPlan.new(text, &block))
7
- Runner.instance.last_test_plan.execute
6
+ reporter = ConsoleReporter.new()
7
+ Runner.instance.add_test_plan(TestPlan.new(text, &block))
8
+ Runner.instance.last_test_plan.execute reporter
8
9
  end
9
10
 
10
11
  class TestPlan
@@ -46,10 +47,10 @@ module Sapphire
46
47
  @handlers << handler
47
48
  end
48
49
 
49
- def execute
50
+ def execute(reporter)
50
51
  $stdout.puts ""
51
52
  @block.call
52
- ConsoleReporter.new().OutputResults
53
+ reporter.OutputResults
53
54
  end
54
55
  end
55
56
  end
@@ -15,7 +15,18 @@ class NullModifier
15
15
 
16
16
  def Evaluate(evaluation)
17
17
  return @modifier.Evaluate(evaluation) if @modifier != nil
18
- evaluation.left.should == evaluation.right if @modifier == nil
18
+
19
+ if(evaluation.left != evaluation.right)
20
+ messages = []
21
+
22
+ messages << "expected: (nil)" if evaluation.left == nil
23
+ messages << "expected: " + evaluation.left.to_s if evaluation.left != nil
24
+ messages << "got: (nil)" if evaluation.right == nil
25
+ messages << "got: " + evaluation.right.to_s if evaluation.right != nil
26
+
27
+ raise ExpectationException.new(messages)
28
+ end
29
+ #evaluation.left.should == evaluation.right if @modifier == nil
19
30
  end
20
31
 
21
32
  def execute
@@ -0,0 +1,118 @@
1
+ require 'teamcity/utils/logger_util'
2
+ require 'teamcity/rake_exceptions'
3
+ require 'teamcity/rakerunner_consts'
4
+
5
+ SPEC_FORMATTER_LOG = ::Rake::TeamCity::Utils::RSpecFileLogger.new
6
+ SPEC_FORMATTER_LOG.log_msg("spec formatter.rb loaded.")
7
+
8
+ require 'teamcity/runner_common'
9
+ require 'teamcity/utils/service_message_factory'
10
+ require 'teamcity/utils/std_capture_helper'
11
+ require 'teamcity/utils/runner_utils'
12
+ require 'teamcity/utils/url_formatter'
13
+
14
+ module Sapphire
15
+ module Testing
16
+ module TeamCity
17
+ class TeamCityReporter < Reporter
18
+ include ::Rake::TeamCity::StdCaptureHelper
19
+ include ::Rake::TeamCity::RunnerUtils
20
+ include ::Rake::TeamCity::RunnerCommon
21
+ include ::Rake::TeamCity::Utils::UrlFormatter
22
+
23
+ TEAMCITY_FORMATTER_INTERNAL_ERRORS =[]
24
+ @@reporter_closed = false
25
+ @@RUNNING_EXAMPLES_STORAGE = {}
26
+
27
+ ########## Teamcity #############################
28
+
29
+ def log(msg)
30
+ send_msg(msg)
31
+
32
+ # returns:
33
+ msg
34
+ end
35
+
36
+ def self.closed?()
37
+ @@reporter_closed
38
+ end
39
+
40
+ def self.close()
41
+ @@reporter_closed = true
42
+ end
43
+
44
+ ########## Teamcity #############################
45
+
46
+ def initialize()
47
+ # Setups Test runner's MessageFactory
48
+ set_message_factory(::Rake::TeamCity::MessageFactory)
49
+
50
+ # Initializes
51
+ @groups_stack = []
52
+
53
+ @example_count = 100
54
+ if ::Rake::TeamCity.is_in_idea_mode
55
+ log(@message_factory.create_tests_count(@example_count))
56
+ elsif ::Rake::TeamCity.is_in_buildserver_mode
57
+ log(@message_factory.create_progress_message("Starting.. (#{@example_count} examples)"))
58
+ end
59
+
60
+ end
61
+
62
+ def PrintItem(result, depth)
63
+
64
+ end
65
+
66
+ def ScenarioStart(scenario)
67
+ @message_factory.create_suite_started(scenario.text, scenario.file_name)
68
+ end
69
+
70
+ def ScenarioComplete(scenario)
71
+ @message_factory.create_suite_finished(scenario.text)
72
+ end
73
+
74
+ def PrintHeader()
75
+
76
+ end
77
+
78
+ def PrintFooter()
79
+
80
+ end
81
+
82
+ def InsertLineBreak()
83
+
84
+ end
85
+
86
+ def PrePrint
87
+
88
+ end
89
+
90
+ def PostPrint
91
+
92
+ end
93
+
94
+ def TestStarted(test)
95
+ @@RUNNING_EXAMPLES_STORAGE[test.object_id] = test
96
+ end
97
+
98
+ def TestCompleted(test)
99
+ if test.type == "pending"
100
+ @message_factory.create_test_output_message(test.text, true, "Pending: Not Yet Implemented")
101
+ @message_factory.create_test_ignored(test.text, "Pending: Not Yet Implemented")
102
+ return
103
+ end
104
+ if test.type == "pass"
105
+ @message_factory.create_test_finished(test.text, test.time)
106
+ return
107
+ end
108
+ if test.type == "fail"
109
+ @message_factory.create_test_output_message(test.text, true, "enter error here")
110
+ @message_factory.create_test_failed(test.text, test.message, "enter backtrace here")
111
+ end
112
+
113
+ @@RUNNING_EXAMPLES_STORAGE.delete(test.object_id)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -13,8 +13,24 @@ module Sapphire
13
13
  $stdout.puts " ## Not Yet Implemented ##"
14
14
  else
15
15
  $stdout.puts result.text.red
16
- Indent(depth+1)
17
- $stdout.puts result.message
16
+ if result.messages.is_a? Array
17
+ result.messages.each do |message|
18
+ Indent(depth+1)
19
+ $stdout.puts message
20
+ end
21
+
22
+ else
23
+ Indent(depth+1)
24
+ $stdout.puts result.messages
25
+ end
26
+ $stdout.puts ""
27
+ result.stack.each do |line|
28
+ if (!line.include? "sapphire")
29
+ Indent(depth+1)
30
+ $stdout.puts line
31
+ end
32
+ end
33
+
18
34
  end
19
35
  end
20
36
 
@@ -22,6 +38,14 @@ module Sapphire
22
38
  $stdout.puts ""
23
39
  end
24
40
 
41
+ def ScenarioStart(scenario)
42
+ $stdout.puts scenario.file_name + ": "
43
+ end
44
+
45
+ def ScenarioComplete(scenario)
46
+ $stdout.puts ""
47
+ end
48
+
25
49
  def PrintFooter()
26
50
  $stdout.puts ""
27
51
  $stdout.puts "Finished in " + self.time.round(2).to_s + " seconds."
@@ -48,6 +72,17 @@ module Sapphire
48
72
  def PostPrint
49
73
 
50
74
  end
75
+
76
+ def TestStarted(test)
77
+
78
+ end
79
+
80
+ def TestCompleted(test)
81
+ $stdout.print "*".yellow if test.type == "pending"
82
+ $stdout.print ".".green if test.type == "pass"
83
+ $stdout.print "F".red if test.type == "fail"
84
+ end
85
+
51
86
  end
52
87
  end
53
88
  end
@@ -1,28 +1,29 @@
1
1
  module Sapphire
2
2
  module Testing
3
3
  module Executable
4
- def execute(id)
4
+ def execute(reporter)
5
5
  start = Time.now
6
+ reporter.TestStarted(self.text)
6
7
  begin
7
8
  if(self.value.is_a? Pending)
8
- self.AddResult(ResultTree.new(self.text, TestResult.new("pending", self, "Pending", "", Time.now - start, id)))
9
- $stdout.print "*".yellow
9
+ result = ResultTree.new(self.text, TestResult.new("pending", self, "Pending", "", Time.now - start))
10
+ self.AddResult(result)
11
+ reporter.TestCompleted result
10
12
  return
11
13
  end
12
14
  self.block.call
13
- self.AddResult(ResultTree.new(self.text, TestResult.new("pass", self, "Success", "", Time.now - start, id)))
14
- $stdout.print ".".green
15
+ result = ResultTree.new(self.text, TestResult.new("pass", self, "Success", "", Time.now - start))
16
+ self.AddResult(result)
17
+ reporter.TestCompleted result
15
18
  rescue => msg
16
- stack = ""
17
- msg.backtrace.each do |line|
18
- stack += "\r\n" + line
19
- end
20
-
21
- self.AddResult(ResultTree.new(self.text, TestResult.new("fail", self, msg.message, stack, Time.now - start, id)))
22
- $stdout.print "F".red
19
+ stack = msg.backtrace
20
+ message = msg.messages if (msg.is_a? ExpectationException)
21
+ message ||= msg.message
22
+ result = ResultTree.new(self.text, TestResult.new("fail", self, message, stack, Time.now - start))
23
+ self.AddResult(result)
24
+ reporter.TestCompleted result
23
25
  end
24
26
  end
25
- @result
26
27
  end
27
28
  end
28
29
  end
@@ -0,0 +1,11 @@
1
+ module Sapphire
2
+ module Testing
3
+ class ExpectationException < StandardError
4
+ attr_reader :messages
5
+
6
+ def initialize(messages)
7
+ @messages = messages
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,19 +2,31 @@ module Sapphire
2
2
  module Testing
3
3
  class HtmlReporter < Reporter
4
4
 
5
+ def ScenarioStart(scenario)
6
+
7
+ end
8
+
9
+ def ScenarioComplete
10
+
11
+ end
12
+
13
+ def PrintItem(result, depth)
14
+
15
+ end
16
+
5
17
  def PrintHeader()
6
18
 
7
19
  end
8
20
 
9
- def Output(result, tabber)
21
+ def PrintFooter()
10
22
 
11
23
  end
12
24
 
13
- def PrePrint
25
+ def InsertLineBreak()
14
26
 
15
27
  end
16
28
 
17
- def PrintResult(entry)
29
+ def PrePrint
18
30
 
19
31
  end
20
32
 
@@ -22,7 +34,11 @@ module Sapphire
22
34
 
23
35
  end
24
36
 
25
- def PrintFooter()
37
+ def TestStarted(test)
38
+
39
+ end
40
+
41
+ def TestCompleted(test)
26
42
 
27
43
  end
28
44
 
@@ -5,7 +5,7 @@ module Sapphire
5
5
  attr_accessor :results
6
6
  attr_accessor :type
7
7
  attr_accessor :text
8
- attr_accessor :message
8
+ attr_accessor :messages
9
9
  attr_accessor :stack
10
10
  attr_accessor :time
11
11
  attr_accessor :parent
@@ -23,7 +23,7 @@ module Sapphire
23
23
  @iconCls = "error" if result.type == "pending"
24
24
  @time = result.execution_time
25
25
  @expanded = true
26
- @message = result.message
26
+ @messages = result.messages
27
27
  @stack = result.stack
28
28
  end
29
29
  @text = text
@@ -4,17 +4,15 @@ module Sapphire
4
4
 
5
5
  attr_reader :execution_time
6
6
  attr_reader :message
7
- attr_reader :myId
8
7
  attr_reader :item
9
8
  attr_reader :type
10
9
  attr_reader :stack
11
- attr_reader :message
10
+ attr_reader :messages
12
11
 
13
- def initialize(type, item, message, stack, execution_time, id)
14
- @myId = id
12
+ def initialize(type, item, message, stack, execution_time)
15
13
  @item = item
16
14
  @execution_time = execution_time
17
- @message = message
15
+ @messages = message
18
16
  @stack = stack
19
17
  @type = type
20
18
  end
@@ -2,14 +2,15 @@ module Sapphire
2
2
  module Testing
3
3
  module TestRunnerAdapter
4
4
 
5
- def execute(id)
5
+ def execute(reporter)
6
+ reporter.ScenarioStart self
6
7
  @failures = []
7
8
  @pendings = []
8
9
  @success = []
9
10
 
10
11
  self.backgrounds.each do |b|
11
12
 
12
- b.execute id
13
+ b.execute reporter
13
14
 
14
15
  end
15
16
 
@@ -17,29 +18,29 @@ module Sapphire
17
18
 
18
19
  g.when.each do |w|
19
20
 
20
- g.execute id
21
+ g.execute reporter
21
22
 
22
23
  g.and.each do |g_a|
23
24
 
24
- g_a.execute id
25
+ g_a.execute reporter
25
26
 
26
27
  end
27
28
 
28
- w.execute id
29
+ w.execute reporter
29
30
 
30
31
  w.and.each do |w_a|
31
32
 
32
- w_a.execute id
33
+ w_a.execute reporter
33
34
 
34
35
  end
35
36
 
36
37
  w.then.each do |t|
37
38
 
38
- t.execute id
39
+ t.execute reporter
39
40
 
40
41
  t.and.each do |t_a|
41
42
 
42
- t_a.execute id
43
+ t_a.execute reporter
43
44
 
44
45
  end
45
46
 
@@ -49,12 +50,14 @@ module Sapphire
49
50
 
50
51
  if(g.finally)
51
52
 
52
- g.finally.execute id
53
+ g.finally.execute reporter
53
54
 
54
55
  end
55
56
 
56
57
  end
57
58
 
59
+ reporter.ScenarioComplete self
60
+
58
61
  end
59
62
  end
60
63
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-22 00:00:00.000000000Z
12
+ date: 2011-09-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &9278508 !ruby/object:Gem::Requirement
16
+ requirement: &9381432 !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: *9278508
24
+ version_requirements: *9381432
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &9278172 !ruby/object:Gem::Requirement
27
+ requirement: &9381132 !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: *9278172
35
+ version_requirements: *9381132
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: win32console
38
- requirement: &9277848 !ruby/object:Gem::Requirement
38
+ requirement: &9380832 !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: *9277848
46
+ version_requirements: *9380832
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email:
@@ -126,14 +126,15 @@ files:
126
126
  - lib/sapphire/Strategies/NullModifier.rb
127
127
  - lib/sapphire/Strategies/Strategy.rb
128
128
  - lib/sapphire/Strategies/SymbolStrategy.rb
129
+ - lib/sapphire/TeamCity/TeamCityReporter.rb
129
130
  - lib/sapphire/Testing/ConsoleReporter.rb
130
131
  - lib/sapphire/Testing/Executable.rb
132
+ - lib/sapphire/Testing/ExpectationException.rb
131
133
  - lib/sapphire/Testing/HtmlReporter.rb
132
134
  - lib/sapphire/Testing/RakeTask.rb
133
135
  - lib/sapphire/Testing/Reporter.rb
134
136
  - lib/sapphire/Testing/ResultList.rb
135
137
  - lib/sapphire/Testing/ResultTree.rb
136
- - lib/sapphire/Testing/RSpecRunner.rb
137
138
  - lib/sapphire/Testing/ScenarioResult.rb
138
139
  - lib/sapphire/Testing/TestResult.rb
139
140
  - lib/sapphire/Testing/TestRunnerAdapter.rb
@@ -1,87 +0,0 @@
1
- module Sapphire
2
- module Testing
3
- module RSpecRunner
4
- def execute(id)
5
- @block.call
6
- s = self
7
- x = @givens
8
- y = @backgrounds
9
- background_pending = false
10
-
11
- y.each do |background|
12
- if(background.value.instance_of? Pending)
13
- background_pending = true
14
- end
15
- end
16
-
17
- x.each do |g|
18
- describe g.text do
19
-
20
- before :all do
21
- y.each do |b|
22
- if(!b.value.instance_of? Pending and !s.value.instance_of? Pending)
23
- b.block.call()
24
- end
25
- end
26
- end
27
-
28
- before :each do
29
- if(!g.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
30
- g.block.call()
31
- g.and.each do |a|
32
- a.block.call()
33
- end
34
- end
35
- end
36
-
37
- g.when.each do |w|
38
- describe w.text do
39
- before do
40
- if(!w.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
41
- w.block.call()
42
-
43
- if (w.and.count > 0)
44
- w.and.each do |a|
45
- a.block.call()
46
- end
47
- end
48
- end
49
- end
50
-
51
- if (w.then.count > 0)
52
- w.then.each do |t|
53
- if(!t.value.instance_of? Pending and !w.value.instance_of? Pending and !g.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
54
- it t.text do
55
- t.block.call()
56
- t.and.each do |a|
57
- if(!a.value.instance_of? Pending)
58
- a.block.call()
59
- end
60
- end
61
- end
62
- else
63
- pending t.text
64
- end
65
- end
66
- end
67
- end
68
- end
69
-
70
- after :all do
71
- if(g.finally and !g.finally.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
72
- g.finally.block.call()
73
-
74
- g.finally.and.each do |a|
75
- a.block.call()
76
- end
77
- end
78
- end
79
- end
80
- end
81
-
82
- true
83
- end
84
- end
85
- end
86
- end
87
-