expectations 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -66,7 +66,24 @@ expectations can be used for state based and behavior based testing.
66
66
  expect Object.to_receive(:deal) do
67
67
  Object.deal
68
68
  end
69
-
69
+
70
+ # State based test utilizing a stub
71
+ expect 2 do
72
+ stub(:two => 2).two
73
+ end
74
+
75
+ # State based test utilizing a concrete mock
76
+ expect 2 do
77
+ Object.expects(:bar).returns 2
78
+ Object.bar
79
+ end
80
+
81
+ # Behavior based test utilizing a stub and a concrete mock
82
+ expect 1 do
83
+ Object.expects(:give_me_three).with(3).returns 1
84
+ Object.give_me_three(stub(:three=>3).three)
85
+ end
86
+
70
87
  end
71
88
 
72
89
  == Contributors
@@ -7,6 +7,14 @@ module Expectations::Results
7
7
  self.is_a?(Expectations::Results::Fulfilled)
8
8
  end
9
9
 
10
+ def failure?
11
+ self.is_a?(Expectations::Results::StateBasedFailure) || self.is_a?(Expectations::Results::BehaviorFailure)
12
+ end
13
+
14
+ def error?
15
+ self.is_a?(Expectations::Results::StateBasedError) || self.is_a?(Expectations::Results::BehaviorBasedError)
16
+ end
17
+
10
18
  def self.included(klass)
11
19
  klass.extend ClassMethods
12
20
  end
@@ -10,7 +10,7 @@ class Expectations::Suite
10
10
  ENV["LINE"].nil? ? run_all(suite_result) : run_one(suite_result)
11
11
  end
12
12
  suite_result.print_results(benchmark)
13
- suite_result.write_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
13
+ suite_result.write_junit_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
14
14
  suite_result.result
15
15
  end
16
16
 
@@ -14,19 +14,15 @@ class Expectations::SuiteResults
14
14
  end
15
15
 
16
16
  def fulfilled
17
- expectations.select { |expectation| expectation.is_a?(Expectations::Results::Fulfilled) }
17
+ expectations.select { |expectation| expectation.fulfilled? }
18
18
  end
19
19
 
20
20
  def errors
21
- expectations.select do |expectation|
22
- expectation.is_a?(Expectations::Results::StateBasedError) || expectation.is_a?(Expectations::Results::BehaviorBasedError)
23
- end
21
+ expectations.select { |expectation| expectation.error? }
24
22
  end
25
23
 
26
24
  def failures
27
- expectations.select do |expectation|
28
- expectation.is_a?(Expectations::Results::StateBasedFailure) || expectation.is_a?(Expectations::Results::BehaviorFailure)
29
- end
25
+ expectations.select { |expectation| expectation.failure? }
30
26
  end
31
27
 
32
28
  def print_results(benchmark)
@@ -57,6 +53,32 @@ class Expectations::SuiteResults
57
53
  end
58
54
  end
59
55
 
56
+ def write_junit_xml(path)
57
+ FileUtils.rm_rf path if File.exist?(path)
58
+ FileUtils.mkdir_p path
59
+ grouped_expectations = expectations.inject({}) do |result, expectation|
60
+ result[expectation.file] = [] if result[expectation.file].nil?
61
+ result[expectation.file] << expectation
62
+ result
63
+ end
64
+ grouped_expectations.keys.each do |file_name|
65
+ class_name = "#{File.basename(file_name, ".rb")}.xml"
66
+ File.open("#{path}/TEST-#{class_name}", "w") do |file|
67
+ file << '<?xml version="1.0" encoding="UTF-8" ?>'
68
+ grouped_fulfilled = grouped_expectations[file_name].select { |expectation| expectation.fulfilled? }
69
+ grouped_errors = grouped_expectations[file_name].select { |expectation| expectation.error? }
70
+ grouped_failures = grouped_expectations[file_name].select { |expectation| expectation.failure? }
71
+ file << %[<testsuite errors="#{grouped_errors.size}" skipped="0" tests="#{grouped_expectations[file_name].size}" time="0.00" failures="#{grouped_failures.size}" name="#{class_name}">]
72
+ grouped_expectations[file_name].each do |expectation|
73
+ file << %[<testcase time="0.0" name="line:#{expectation.line}">]
74
+ file << %[<failure type="java.lang.AssertionError" message="#{ERB::Util.h(expectation.message)}"/>] if expectation.failure?
75
+ file << %[</testcase>]
76
+ end
77
+ file << %[</testsuite>]
78
+ end
79
+ end
80
+ end
81
+
60
82
  def filter_backtrace(trace)
61
83
  patterns_to_strip = [/\/expectations\/lib\/expectations\//, /\/lib\/ruby\/1\.8\//]
62
84
  result = patterns_to_strip.inject(trace) do |result, element|
data/lib/expectations.rb CHANGED
@@ -14,6 +14,8 @@ require 'mocha'
14
14
  require 'mocha/standalone'
15
15
  require 'singleton'
16
16
  require 'benchmark'
17
+ require 'erb'
18
+ require 'fileutils'
17
19
  require File.expand_path(File.dirname(__FILE__) + '/expectations/object')
18
20
  require File.expand_path(File.dirname(__FILE__) + '/expectations/string')
19
21
  require File.expand_path(File.dirname(__FILE__) + '/expectations/mocha')
data/rakefile.rb CHANGED
@@ -41,7 +41,7 @@ specification = Gem::Specification.new do |s|
41
41
  expect NoMethodError do
42
42
  Object.invalid_method_call
43
43
  end."
44
- s.version = "0.0.9"
44
+ s.version = "0.1.0"
45
45
  s.author = 'Jay Fields'
46
46
  s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
47
47
  expect 2 do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-07 00:00:00 -08:00
12
+ date: 2008-01-09 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15