expectations 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -61,4 +61,6 @@ expectations can be used for state based and behavior based testing.
61
61
 
62
62
  end
63
63
 
64
- == Contributors
64
+ == Contributors
65
+
66
+ Matt Mower
@@ -20,10 +20,11 @@ class Expectations::Expectation
20
20
  self.extend(Expectations::Results::Fulfilled)
21
21
  rescue Mocha::ExpectationError => ex
22
22
  self.extend(Expectations::Results::BehaviorFailure)
23
- self.message = ex.message.gsub(/:/,";")
23
+ self.message = ex.message
24
24
  rescue Exception => ex
25
- self.extend(Expectations::Results::Error)
25
+ self.extend(Expectations::Results::BehaviorBasedError)
26
26
  self.exception = ex
27
+ self.message = ""
27
28
  ensure
28
29
  mocha_teardown
29
30
  end
@@ -36,7 +37,7 @@ class Expectations::Expectation
36
37
  return self.extend(Expectations::Results::Fulfilled) if expected == actual
37
38
  rescue Exception => ex
38
39
  return self.extend(Expectations::Results::Fulfilled) if expected == ex.class
39
- self.extend(Expectations::Results::Error)
40
+ self.extend(Expectations::Results::StateBasedError)
40
41
  self.exception = ex
41
42
  self.actual = ex.class if expected.is_a?(Class) && expected < StandardError
42
43
  return self
@@ -46,9 +46,20 @@ module Expectations::Results
46
46
  end
47
47
 
48
48
  module Expectations::Results
49
- module Error
49
+ module BehaviorBasedError
50
+ attr_accessor :exception, :message
51
+ include Expectations::Results
52
+ char "E"
53
+ end
54
+ end
55
+
56
+ module Expectations::Results
57
+ module StateBasedError
50
58
  attr_accessor :exception
51
59
  include Expectations::Results
52
60
  char "E"
61
+ def message
62
+ "expected: <#{expected.inspect}> got: <#{actual.inspect}>"
63
+ end
53
64
  end
54
65
  end
@@ -18,7 +18,9 @@ class Expectations::SuiteResults
18
18
  end
19
19
 
20
20
  def errors
21
- expectations.select { |expectation| expectation.is_a?(Expectations::Results::Error) }
21
+ expectations.select do |expectation|
22
+ expectation.is_a?(Expectations::Results::StateBasedError) || expectation.is_a?(Expectations::Results::BehaviorBasedError)
23
+ end
22
24
  end
23
25
 
24
26
  def failures
@@ -35,18 +37,20 @@ class Expectations::SuiteResults
35
37
  out.puts "\nSuccess: #{fulfilled.size} fulfilled"
36
38
  else
37
39
  out.puts "\nFailure: #{failures.size} failed, #{errors.size} errors, #{fulfilled.size} fulfilled"
38
- out.puts "\nErrors:" if errors.any?
40
+ out.puts "\n--Errors--" if errors.any?
39
41
  errors.each do |error|
40
- out.puts " #{error.file}:#{error.line}:in `expect'"
41
- out.puts " line <#{error.line}>"
42
- out.puts " error <#{error.exception.message.gsub(/:/,";")}>"
43
- out.puts " expected <#{error.expected.inspect}> got <#{error.actual.inspect}>"
42
+ out.puts " #{error.file}:#{error.line}:in `expect'" if ENV["TM_MODE"]
43
+ out.puts "file <#{error.file}>"
44
+ out.puts "line <#{error.line}>"
45
+ out.puts "error <#{error.exception.message}>"
46
+ out.puts "#{error.message}\n\n" if error.message.any?
44
47
  end
45
- out.puts "\nFailures:" if failures.any?
48
+ out.puts "\n--Failures--" if failures.any?
46
49
  failures.each do |failure|
47
- out.puts " #{failure.file}:#{failure.line}:in `expect'"
48
- out.puts " line <#{failure.line}>"
49
- out.puts " #{failure.message}"
50
+ out.puts " #{failure.file}:#{failure.line}:in `expect'" if ENV["TM_MODE"]
51
+ out.puts "file <#{failure.file}>"
52
+ out.puts "line <#{failure.line}>"
53
+ out.puts "#{failure.message}\n\n"
50
54
  end
51
55
  end
52
56
  end
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.3"
44
+ s.version = "0.0.4"
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
@@ -10,7 +10,7 @@ Expectations do
10
10
  end
11
11
 
12
12
  expect true do
13
- Expectations::Expectation.new(1) { raise }.execute.is_a?(Expectations::Results::Error)
13
+ Expectations::Expectation.new(1) { raise }.execute.is_a?(Expectations::Results::StateBasedError)
14
14
  end
15
15
 
16
16
  expect NoMethodError do
@@ -15,7 +15,7 @@ Expectations do
15
15
  end
16
16
 
17
17
  expect "E" do
18
- Object.new.extend(Expectations::Results::Error).char
18
+ Object.new.extend(Expectations::Results::BehaviorBasedError).char
19
19
  end
20
20
 
21
21
  expect true do
@@ -31,7 +31,7 @@ Expectations do
31
31
  end
32
32
 
33
33
  expect false do
34
- Object.new.extend(Expectations::Results::Error).fulfilled?
34
+ Object.new.extend(Expectations::Results::BehaviorBasedError).fulfilled?
35
35
  end
36
36
 
37
37
  end
@@ -23,4 +23,16 @@ Expectations do
23
23
  Object.deal(1)
24
24
  end
25
25
 
26
+ # expect Object.to_receive(:deal).with(1) do
27
+ # Object.deals(1)
28
+ # end
29
+ #
30
+ # expect Object.to_receive(:deal).with(1) do
31
+ # Object.deal(2)
32
+ # end
33
+ #
34
+ # expect Object.to_receive(:deal).with(1) do
35
+ # Object.deal(1)
36
+ # end
37
+
26
38
  end
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields