expectations 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,10 +20,6 @@ module Expectations::MockRecorder
20
20
  subject
21
21
  end
22
22
 
23
- def verify
24
- subject.verify
25
- end
26
-
27
23
  def mocha_error_message(ex)
28
24
  ex.message
29
25
  end
@@ -6,7 +6,7 @@ module Expectations::RecordedExpectation
6
6
  warn_for_expects do
7
7
  instance_exec(expected.subject, &block) if block
8
8
  end
9
- if expected.verify! && mocha_verify
9
+ if mocha_verify
10
10
  self.extend(Expectations::Results::Fulfilled)
11
11
  else
12
12
  self.extend(Expectations::Results::StateBasedFailure)
@@ -1,12 +1,22 @@
1
1
  class Expectations::StandardError
2
+ class << self
3
+ attr_accessor :outlet
4
+ end
5
+
6
+ self.outlet = STDERR
7
+
8
+ def self.silence
9
+ self.outlet = Silent
10
+ end
11
+
2
12
  def self.print(string)
3
13
  print_suggestion
4
- STDERR.print string
14
+ outlet.print string
5
15
  end
6
16
 
7
17
  def self.print_suggestion
8
18
  return if @suggestion_printed
9
19
  @suggestion_printed = true
10
- STDERR.print "Expectations allows you to to create multiple mock expectations, but suggests that you write another test instead.\n"
20
+ outlet.print "Expectations allows you to to create multiple mock expectations, but suggests that you write another test instead.\n"
11
21
  end
12
22
  end
@@ -1,6 +1,9 @@
1
1
  class Expectations::Suite
2
2
 
3
3
  include Mocha::Standalone
4
+ class << self
5
+ attr_accessor :silent
6
+ end
4
7
 
5
8
  def initialize
6
9
  @do_not_run = false
@@ -21,7 +24,7 @@ class Expectations::Suite
21
24
  end
22
25
 
23
26
  def expect(expected, &block)
24
- expectations << Expectations::Expectation.new(expected, *caller.first.split(/:/)[0..1], &block)
27
+ expectations << Expectations::Expectation.new(expected, *caller.first.match(/\A(.+):(\d+)\Z/)[1..2], &block)
25
28
  end
26
29
 
27
30
  def do_not_run
data/rakefile.rb CHANGED
@@ -46,7 +46,7 @@ specification = Gem::Specification.new do |s|
46
46
  expect NoMethodError do
47
47
  Object.invalid_method_call
48
48
  end."
49
- s.version = "1.0.0"
49
+ s.version = "1.1.0"
50
50
  s.author = 'Jay Fields'
51
51
  s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
52
52
  expect 2 do
@@ -1,69 +1,20 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
3
  Expectations do
4
-
5
- expect "." do
6
- Object.new.extend(Expectations::Results::Fulfilled).char
7
- end
8
-
9
- expect "F" do
10
- Object.new.extend(Expectations::Results::StateBasedFailure).char
11
- end
12
-
13
- expect "F" do
14
- Object.new.extend(Expectations::Results::BehaviorBasedFailure).char
15
- end
16
-
17
- expect "E" do
18
- Object.new.extend(Expectations::Results::Error).char
19
- end
20
-
21
- expect Object.new.to.be.fulfilled? do |instance|
22
- instance.extend(Expectations::Results::Fulfilled)
23
- end
24
-
25
- expect Object.new.not.to.be.fulfilled? do |instance|
26
- instance.extend(Expectations::Results::StateBasedFailure)
27
- end
28
-
29
- expect Object.new.not.to.be.fulfilled? do |instance|
30
- instance.extend(Expectations::Results::BehaviorBasedFailure)
31
- end
32
-
33
- expect Object.new.not.to.be.fulfilled? do |instance|
34
- instance.extend(Expectations::Results::Error)
35
- end
36
-
37
- expect Object.new.not.to.be.error? do |instance|
38
- instance.extend(Expectations::Results::Fulfilled)
39
- end
40
-
41
- expect Object.new.not.to.be.error? do |instance|
42
- instance.extend(Expectations::Results::StateBasedFailure)
43
- end
44
-
45
- expect Object.new.not.to.be.error? do |instance|
46
- instance.extend(Expectations::Results::BehaviorBasedFailure)
47
- end
48
-
49
- expect Object.new.to.be.error? do |instance|
50
- instance.extend(Expectations::Results::Error)
51
- end
52
-
53
- expect Object.new.not.to.be.failure? do |instance|
54
- instance.extend(Expectations::Results::Fulfilled)
55
- end
56
-
57
- expect Object.new.to.be.failure? do |instance|
58
- instance.extend(Expectations::Results::StateBasedFailure)
59
- end
60
-
61
- expect Object.new.to.be.failure? do |instance|
62
- instance.extend(Expectations::Results::BehaviorBasedFailure)
63
- end
64
-
65
- expect Object.new.not.to.be.failure? do |instance|
66
- instance.extend(Expectations::Results::Error)
67
- end
68
-
4
+ expect Object.new.extend(Expectations::Results::Fulfilled).to.have.char == "."
5
+ expect Object.new.extend(Expectations::Results::StateBasedFailure).to.have.char == "F"
6
+ expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).to.have.char == "F"
7
+ expect Object.new.extend(Expectations::Results::Error).to.have.char == "E"
8
+ expect Object.new.extend(Expectations::Results::Fulfilled).to.be.fulfilled?
9
+ expect Object.new.extend(Expectations::Results::StateBasedFailure).not.to.be.fulfilled?
10
+ expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).not.to.be.fulfilled?
11
+ expect Object.new.extend(Expectations::Results::Error).not.to.be.fulfilled?
12
+ expect Object.new.extend(Expectations::Results::Fulfilled).not.to.be.error?
13
+ expect Object.new.extend(Expectations::Results::StateBasedFailure).not.to.be.error?
14
+ expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).not.to.be.error?
15
+ expect Object.new.extend(Expectations::Results::Error).to.be.error?
16
+ expect Object.new.extend(Expectations::Results::Fulfilled).not.to.be.failure?
17
+ expect Object.new.extend(Expectations::Results::StateBasedFailure).to.be.failure?
18
+ expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).to.be.failure?
19
+ expect Object.new.extend(Expectations::Results::Error).not.to.be.failure?
69
20
  end
@@ -1,17 +1,9 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
3
  Expectations do
4
- expect true do
5
- Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>"
6
- end
7
-
8
- expect false do
9
- Expectations::XmlString.new("<foo>not bar</foo>").expectations_equal_to "<foo>bar</foo>"
10
- end
11
-
12
- expect false do
13
- Expectations::XmlString.new("<not-foo>bar</not-foo>").expectations_equal_to "<foo>bar</foo>"
14
- end
4
+ expect Expectations::XmlString.new("<foo>bar</foo>").to.be.expectations_equal_to("<foo>bar</foo>")
5
+ expect Expectations::XmlString.new("<foo>not bar</foo>").not.to.be.expectations_equal_to("<foo>bar</foo>")
6
+ expect Expectations::XmlString.new("<not-foo>bar</not-foo>").not.to.be.expectations_equal_to("<foo>bar</foo>")
15
7
 
16
8
  expect true do
17
9
  Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to " <foo>bar</foo> "
@@ -12,10 +12,11 @@ Expectations do
12
12
  suite.expect(ArgumentError) { Object.no_method }
13
13
  suite.execute(Silent).expectations.first
14
14
  end
15
-
15
+
16
16
  expect Expectations::Results::BehaviorBasedFailure do
17
+ Expectations::StandardError.silence
17
18
  suite = Expectations::Suite.new
18
- suite.expect Mocha::Mock.new.to.receive(:dial).with("2125551212").times(2) do |phone|
19
+ suite.expect mock.to.receive(:dial).with("2125551212").times(2) do |phone|
19
20
  phone.dial("2125551212")
20
21
  phone.dial("2125551212")
21
22
  phone.dial("2125551212")
@@ -26,25 +27,25 @@ Expectations do
26
27
  expect Expectations::Results::BehaviorBasedFailure do
27
28
  Expectations::StandardError.stubs(:print)
28
29
  suite = Expectations::Suite.new
29
- suite.expect Mocha::Mock.new.to.receive(:dial).with("2125551212").times(2) do |phone|
30
+ suite.expect mock.to.receive(:dial).with("2125551212").times(2) do |phone|
30
31
  phone.dial("2125551212")
31
32
  end
32
33
  suite.execute(Silent).expectations.first
33
34
  end
34
-
35
+
35
36
  expect Expectations::Results::BehaviorBasedFailure do
36
37
  Expectations::StandardError.stubs(:print)
37
38
  suite = Expectations::Suite.new
38
39
  suite.expect(Object.to.receive(:deal)) { }
39
40
  suite.execute(Silent).expectations.first
40
41
  end
41
-
42
+
42
43
  expect Expectations::Results::Error do
43
44
  suite = Expectations::Suite.new
44
45
  suite.expect(2) { stub(:two => 2).twos }
45
46
  suite.execute(Silent).expectations.first
46
47
  end
47
-
48
+
48
49
  expect Expectations::Results::Error do
49
50
  Expectations::StandardError.stubs(:print)
50
51
  suite = Expectations::Suite.new
@@ -54,7 +55,7 @@ Expectations do
54
55
  end
55
56
  suite.execute(Silent).expectations.first
56
57
  end
57
-
58
+
58
59
  expect Expectations::Results::Error do
59
60
  Expectations::StandardError.stubs(:print)
60
61
  suite = Expectations::Suite.new
@@ -64,7 +65,7 @@ Expectations do
64
65
  end
65
66
  suite.execute(Silent).expectations.first
66
67
  end
67
-
68
+
68
69
  expect Expectations::Results::Error do
69
70
  Expectations::StandardError.stubs(:print)
70
71
  suite = Expectations::Suite.new
@@ -73,7 +74,7 @@ Expectations do
73
74
  end
74
75
  suite.execute(Silent).expectations.first
75
76
  end
76
-
77
+
77
78
  expect Expectations::Results::Error do
78
79
  Expectations::StandardError.stubs(:print)
79
80
  suite = Expectations::Suite.new
@@ -102,5 +103,5 @@ Expectations do
102
103
  end
103
104
  suite.execute(Silent).expectations.first
104
105
  end
105
-
106
+
106
107
  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: 1.0.0
4
+ version: 1.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-05-18 00:00:00 +01:00
12
+ date: 2008-07-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency