spicycode-micronaut 0.2.1.5 → 0.2.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems/specification'
4
4
  require 'lib/micronaut/rake_task'
5
5
 
6
6
  GEM = "micronaut"
7
- GEM_VERSION = "0.2.1.5"
7
+ GEM_VERSION = "0.2.1.6"
8
8
  AUTHOR = "Chad Humphries"
9
9
  EMAIL = "chad@spicycode.com"
10
10
  HOMEPAGE = "http://github.com/spicycode/micronaut"
@@ -60,7 +60,7 @@ describe Micronaut::Behaviour do
60
60
  end
61
61
 
62
62
  it "should add the caller to metadata" do
63
- Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller].should include("#{__FILE__}:#{__LINE__}")
63
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/
64
64
  end
65
65
 
66
66
  it "should add the the file_path to metadata" do
@@ -68,5 +68,79 @@ describe Object do
68
68
  end
69
69
 
70
70
  end
71
+
72
+ module ExampleExpectations
73
+
74
+ class ArbitraryMatcher
75
+ def initialize(*args, &block)
76
+ if args.last.is_a? Hash
77
+ @expected = args.last[:expected]
78
+ end
79
+ if block_given?
80
+ @expected = block.call
81
+ end
82
+ @block = block
83
+ end
84
+
85
+ def matches?(target)
86
+ @target = target
87
+ return @expected == target
88
+ end
89
+
90
+ def with(new_value)
91
+ @expected = new_value
92
+ self
93
+ end
94
+
95
+ def failure_message
96
+ "expected #{@expected}, got #{@target}"
97
+ end
98
+
99
+ def negative_failure_message
100
+ "expected not #{@expected}, got #{@target}"
101
+ end
102
+ end
103
+
104
+ class PositiveOnlyMatcher < ArbitraryMatcher
105
+ undef negative_failure_message rescue nil
106
+ end
107
+
108
+ def arbitrary_matcher(*args, &block)
109
+ ArbitraryMatcher.new(*args, &block)
110
+ end
111
+
112
+ def positive_only_matcher(*args, &block)
113
+ PositiveOnlyMatcher.new(*args, &block)
114
+ end
115
+
116
+ end
117
+
118
+ describe "should and should not matcher handling" do
119
+ include ExampleExpectations
120
+
121
+ it "should handle submitted args" do
122
+ 5.should arbitrary_matcher(:expected => 5)
123
+ 5.should arbitrary_matcher(:expected => "wrong").with(5)
124
+ lambda { 5.should arbitrary_matcher(:expected => 4) }.should fail_with("expected 4, got 5")
125
+ lambda { 5.should arbitrary_matcher(:expected => 5).with(4) }.should fail_with("expected 4, got 5")
126
+ 5.should_not arbitrary_matcher(:expected => 4)
127
+ 5.should_not arbitrary_matcher(:expected => 5).with(4)
128
+ lambda { 5.should_not arbitrary_matcher(:expected => 5) }.should fail_with("expected not 5, got 5")
129
+ lambda { 5.should_not arbitrary_matcher(:expected => 4).with(5) }.should fail_with("expected not 5, got 5")
130
+ end
131
+
132
+ it "should handle the submitted block" do
133
+ 5.should arbitrary_matcher { 5 }
134
+ 5.should arbitrary_matcher(:expected => 4) { 5 }
135
+ 5.should arbitrary_matcher(:expected => 4).with(5) { 3 }
136
+ end
137
+
138
+ it "should explain when matcher does not support should_not" do
139
+ lambda {
140
+ 5.should_not positive_only_matcher(:expected => 5)
141
+ }.should fail_with(/Matcher does not support should_not.\n/)
142
+ end
143
+
144
+ end
71
145
 
72
146
  end
@@ -42,11 +42,11 @@ describe Micronaut::Matchers do
42
42
  actual.should be_foo
43
43
  end.should raise_error(/aaaah/)
44
44
  end
45
-
45
+
46
46
  end
47
47
 
48
48
  describe "should_not be_predicate" do
49
-
49
+
50
50
  it "should pass when actual returns false for :sym?" do
51
51
  actual = stub("actual", :happy? => false)
52
52
  actual.should_not be_happy
@@ -64,11 +64,11 @@ describe Micronaut::Matchers do
64
64
  Object.new.should_not be_happy
65
65
  end.should raise_error(NameError)
66
66
  end
67
-
67
+
68
68
  end
69
69
 
70
70
  describe "should be_predicate(*args)" do
71
-
71
+
72
72
  it "should pass when actual returns true for :predicate?(*args)" do
73
73
  actual = mock("actual")
74
74
  actual.expects(:older_than?).with(3).returns(true)
@@ -88,11 +88,11 @@ describe Micronaut::Matchers do
88
88
  Object.new.should be_older_than(3)
89
89
  end.should raise_error(NameError)
90
90
  end
91
-
91
+
92
92
  end
93
93
 
94
94
  describe "should_not be_predicate(*args)" do
95
-
95
+
96
96
  it "should pass when actual returns false for :predicate?(*args)" do
97
97
  actual = mock("actual")
98
98
  actual.expects(:older_than?).with(3).returns(false)
@@ -112,11 +112,11 @@ describe Micronaut::Matchers do
112
112
  Object.new.should_not be_older_than(3)
113
113
  end.should raise_error(NameError)
114
114
  end
115
-
115
+
116
116
  end
117
117
 
118
118
  describe "should be_true" do
119
-
119
+
120
120
  it "should pass when actual equal(true)" do
121
121
  true.should be_true
122
122
  end
@@ -126,11 +126,11 @@ describe Micronaut::Matchers do
126
126
  false.should be_true
127
127
  end.should fail_with("expected true, got false")
128
128
  end
129
-
129
+
130
130
  end
131
131
 
132
132
  describe "should be_false" do
133
-
133
+
134
134
  it "should pass when actual equal(false)" do
135
135
  false.should be_false
136
136
  end
@@ -140,11 +140,11 @@ describe Micronaut::Matchers do
140
140
  true.should be_false
141
141
  end.should fail_with("expected false, got true")
142
142
  end
143
-
143
+
144
144
  end
145
145
 
146
146
  describe "should be_nil" do
147
-
147
+
148
148
  it "should pass when actual is nil" do
149
149
  nil.should be_nil
150
150
  end
@@ -154,11 +154,11 @@ describe Micronaut::Matchers do
154
154
  :not_nil.should be_nil
155
155
  end.should fail_with("expected nil? to return true, got false")
156
156
  end
157
-
157
+
158
158
  end
159
159
 
160
160
  describe "should_not be_nil" do
161
-
161
+
162
162
  it "should pass when actual is not nil" do
163
163
  :not_nil.should_not be_nil
164
164
  end
@@ -168,11 +168,11 @@ describe Micronaut::Matchers do
168
168
  nil.should_not be_nil
169
169
  end.should fail_with("expected nil? to return false, got true")
170
170
  end
171
-
171
+
172
172
  end
173
173
 
174
174
  describe "should be <" do
175
-
175
+
176
176
  it "should pass when < operator returns true" do
177
177
  3.should be < 4
178
178
  end
@@ -180,11 +180,11 @@ describe Micronaut::Matchers do
180
180
  it "should fail when < operator returns false" do
181
181
  lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
182
182
  end
183
-
183
+
184
184
  end
185
185
 
186
186
  describe "should be <=" do
187
-
187
+
188
188
  it "should pass when <= operator returns true" do
189
189
  3.should be <= 4
190
190
  4.should be <= 4
@@ -193,11 +193,11 @@ describe Micronaut::Matchers do
193
193
  it "should fail when <= operator returns false" do
194
194
  lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
195
195
  end
196
-
196
+
197
197
  end
198
198
 
199
199
  describe "should be >=" do
200
-
200
+
201
201
  it "should pass when >= operator returns true" do
202
202
  4.should be >= 4
203
203
  5.should be >= 4
@@ -206,11 +206,11 @@ describe Micronaut::Matchers do
206
206
  it "should fail when >= operator returns false" do
207
207
  lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
208
208
  end
209
-
209
+
210
210
  end
211
211
 
212
212
  describe "should be >" do
213
-
213
+
214
214
  it "should pass when > operator returns true" do
215
215
  5.should be > 4
216
216
  end
@@ -218,11 +218,11 @@ describe Micronaut::Matchers do
218
218
  it "should fail when > operator returns false" do
219
219
  lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
220
220
  end
221
-
221
+
222
222
  end
223
223
 
224
224
  describe "should be ==" do
225
-
225
+
226
226
  it "should pass when == operator returns true" do
227
227
  5.should be == 5
228
228
  end
@@ -230,11 +230,11 @@ describe Micronaut::Matchers do
230
230
  it "should fail when == operator returns false" do
231
231
  lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
232
232
  end
233
-
233
+
234
234
  end
235
235
 
236
236
  describe "should be ===" do
237
-
237
+
238
238
  it "should pass when === operator returns true" do
239
239
  Hash.should be === Hash.new
240
240
  end
@@ -242,21 +242,21 @@ describe Micronaut::Matchers do
242
242
  it "should fail when === operator returns false" do
243
243
  lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
244
244
  end
245
-
245
+
246
246
  end
247
247
 
248
248
  describe "should_not with operators" do
249
-
249
+
250
250
  it "should coach user to stop using operators with should_not" do
251
251
  lambda do
252
252
  5.should_not be < 6
253
253
  end.should raise_error(/not only FAILED,\nit reads really poorly./m)
254
254
  end
255
-
255
+
256
256
  end
257
257
 
258
258
  describe "should be" do
259
-
259
+
260
260
  it "should pass if actual is true or a set value" do
261
261
  true.should be
262
262
  1.should be
@@ -269,30 +269,30 @@ describe Micronaut::Matchers do
269
269
  it "should fail if actual is nil" do
270
270
  lambda {nil.should be}.should fail_with("expected true, got nil")
271
271
  end
272
-
272
+
273
273
  end
274
274
 
275
275
  describe "should be(value)" do
276
-
276
+
277
277
  it "should pass if actual.equal?(value)" do
278
278
  5.should be(5)
279
279
  end
280
-
280
+
281
281
  it "should fail if !actual.equal?(value)" do
282
282
  lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
283
283
  end
284
-
284
+
285
285
  end
286
286
 
287
287
  describe "'should be' with operator" do
288
-
288
+
289
289
  it "should include 'be' in the description" do
290
290
  (be > 6).description.should =~ /be > 6/
291
291
  (be >= 6).description.should =~ /be >= 6/
292
292
  (be <= 6).description.should =~ /be <= 6/
293
293
  (be < 6).description.should =~ /be < 6/
294
294
  end
295
-
295
+
296
296
  end
297
297
 
298
298
  end
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
3
3
  describe Micronaut::Matchers, "have" do
4
4
 
5
5
  before do
6
- unless defined?(ActiveSupport::Inflector)
6
+ unless defined?(::ActiveSupport::Inflector)
7
7
  @active_support_was_not_defined
8
- module ActiveSupport
8
+ module ::ActiveSupport
9
9
  class Inflector
10
10
  def self.pluralize(string)
11
11
  string.to_s + 's'
@@ -76,9 +76,9 @@ describe Micronaut::Matchers, "have" do
76
76
  describe 'should have(1).item when Inflector is defined' do
77
77
 
78
78
  before do
79
- unless defined?(Inflector)
79
+ unless defined?(::Inflector)
80
80
  @inflector_was_not_defined
81
- class Inflector
81
+ class ::Inflector
82
82
  def self.pluralize(string)
83
83
  string.to_s + 's'
84
84
  end
@@ -220,6 +220,6 @@ module Micronaut
220
220
  def self.to_s
221
221
  self == Micronaut::Behaviour ? 'Micronaut::Behaviour' : name
222
222
  end
223
-
223
+
224
224
  end
225
- end
225
+ end
@@ -20,21 +20,20 @@ module Micronaut
20
20
  end
21
21
 
22
22
  def run_before_each
23
- @behaviour_instance._setup_mocks
23
+ @behaviour_instance._setup_mocks if @behaviour_instance.respond_to?(:_setup_mocks)
24
24
  @behaviour.eval_before_eachs(@behaviour_instance)
25
25
  end
26
26
 
27
27
  def run_after_each
28
28
  @behaviour.eval_after_eachs(@behaviour_instance)
29
- @behaviour_instance._verify_mocks
29
+ @behaviour_instance._verify_mocks if @behaviour_instance.respond_to?(:_verify_mocks)
30
30
  ensure
31
- @behaviour_instance._teardown_mocks
31
+ @behaviour_instance._teardown_mocks if @behaviour_instance.respond_to?(:_teardown_mocks)
32
32
  end
33
33
 
34
34
  def run_example
35
35
  if example_block
36
36
  @behaviour_instance.instance_eval(&example_block)
37
- @behaviour_instance._verify_mocks
38
37
  @reporter.example_passed(self)
39
38
  else
40
39
  @reporter.example_pending(self, 'Not yet implemented')
@@ -1,6 +1,5 @@
1
1
  require 'micronaut/matchers'
2
2
  require 'micronaut/expectations/extensions/object'
3
- require 'micronaut/expectations/extensions/string_and_symbol'
4
3
  require 'micronaut/expectations/handler'
5
4
  require 'micronaut/expectations/wrap_expectation'
6
5
 
@@ -1,6 +1,7 @@
1
1
  module Micronaut
2
2
  module Expectations
3
- # We add #should and #should_not to every Object (and, implicitly, every Class).
3
+ class InvalidMatcherError < ArgumentError; end
4
+
4
5
  module ObjectExpectations
5
6
  # :call-seq:
6
7
  # should(matcher)
@@ -23,11 +24,21 @@ module Micronaut
23
24
  # See Micronaut::Matchers for more information about matchers
24
25
  #
25
26
  # == Warning
26
- #
27
27
  # NOTE that this does NOT support receiver.should != expected.
28
28
  # Instead, use receiver.should_not == expected
29
29
  def should(matcher=nil, &block)
30
- ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
30
+ ::Micronaut::Matchers.last_should = "should"
31
+ return ::Micronaut::Matchers::PositiveOperatorMatcher.new(self) if matcher.nil?
32
+
33
+ unless matcher.respond_to?(:matches?)
34
+ raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
35
+ end
36
+
37
+ match_found = matcher.matches?(self, &block)
38
+ ::Micronaut::Matchers.last_matcher = matcher
39
+
40
+ ::Micronaut::Expectations.fail_with(matcher.failure_message) unless match_found
41
+ match_found
31
42
  end
32
43
 
33
44
  # :call-seq:
@@ -50,7 +61,26 @@ module Micronaut
50
61
  #
51
62
  # See Micronaut::Matchers for more information about matchers
52
63
  def should_not(matcher=nil, &block)
53
- NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
64
+ ::Micronaut::Matchers.last_should = "should not"
65
+ return ::Micronaut::Matchers::NegativeOperatorMatcher.new(self) if matcher.nil?
66
+
67
+ unless matcher.respond_to?(:matches?)
68
+ raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
69
+ end
70
+
71
+ unless matcher.respond_to?(:negative_failure_message)
72
+ ::Micronaut::Expectations.fail_with(
73
+ <<-EOF
74
+ Matcher does not support should_not.
75
+ See Micronaut::Matchers for more information about matchers.
76
+ EOF
77
+ )
78
+ end
79
+ match_found = matcher.matches?(self, &block)
80
+ ::Micronaut::Matchers.last_matcher = matcher
81
+
82
+ ::Micronaut::Expectations.fail_with(matcher.negative_failure_message) if match_found
83
+ match_found
54
84
  end
55
85
 
56
86
  end
@@ -59,4 +89,4 @@ end
59
89
 
60
90
  class Object
61
91
  include Micronaut::Expectations::ObjectExpectations
62
- end
92
+ end
@@ -1,52 +1,51 @@
1
1
  module Micronaut
2
2
  module Expectations
3
- class InvalidMatcherError < ArgumentError; end
4
3
 
5
- class ExpectationMatcherHandler
6
4
 
7
- def self.handle_matcher(actual, matcher, &block)
8
- ::Micronaut::Matchers.last_should = "should"
9
- return Micronaut::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
10
-
11
- unless matcher.respond_to?(:matches?)
12
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
13
- end
14
-
15
- match = matcher.matches?(actual, &block)
16
- ::Micronaut::Matchers.last_matcher = matcher
17
- Micronaut::Expectations.fail_with(matcher.failure_message) unless match
18
- match
19
- end
20
-
21
- end
22
-
23
- class NegativeExpectationMatcherHandler
24
-
25
- def self.handle_matcher(actual, matcher, &block)
26
- ::Micronaut::Matchers.last_should = "should not"
27
- return Micronaut::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
28
-
29
- unless matcher.respond_to?(:matches?)
30
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
31
- end
32
-
33
- unless matcher.respond_to?(:negative_failure_message)
34
- Micronaut::Expectations.fail_with(
35
- <<-EOF
36
- Matcher does not support should_not.
37
- See Micronaut::Matchers for more information
38
- about matchers.
39
- EOF
40
- )
41
- end
42
- match = matcher.matches?(actual, &block)
43
- ::Micronaut::Matchers.last_matcher = matcher
44
- Micronaut::Expectations.fail_with(matcher.negative_failure_message) if match
45
- match
46
- end
47
-
48
- end
5
+ # class ExpectationMatcherHandler
6
+ #
7
+ # def self.handle_matcher(actual, matcher, &block)
8
+ # ::Micronaut::Matchers.last_should = "should"
9
+ # return Micronaut::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
10
+ #
11
+ # unless matcher.respond_to?(:matches?)
12
+ # raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
13
+ # end
14
+ #
15
+ # match = matcher.matches?(actual, &block)
16
+ # ::Micronaut::Matchers.last_matcher = matcher
17
+ # Micronaut::Expectations.fail_with(matcher.failure_message) unless match
18
+ # match
19
+ # end
20
+ #
21
+ # end
22
+
23
+ # class NegativeExpectationMatcherHandler
24
+ #
25
+ # def self.handle_matcher(actual, matcher, &block)
26
+ # ::Micronaut::Matchers.last_should = "should not"
27
+ # return Micronaut::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
28
+ #
29
+ # unless matcher.respond_to?(:matches?)
30
+ # raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
31
+ # end
32
+ #
33
+ # unless matcher.respond_to?(:negative_failure_message)
34
+ # Micronaut::Expectations.fail_with(
35
+ # <<-EOF
36
+ # Matcher does not support should_not.
37
+ # See Micronaut::Matchers for more information
38
+ # about matchers.
39
+ # EOF
40
+ # )
41
+ # end
42
+ # match = matcher.matches?(actual, &block)
43
+ # ::Micronaut::Matchers.last_matcher = matcher
44
+ # Micronaut::Expectations.fail_with(matcher.negative_failure_message) if match
45
+ # match
46
+ # end
47
+
48
+ # end
49
49
 
50
50
  end
51
- end
52
-
51
+ end
@@ -117,6 +117,14 @@ module Micronaut
117
117
  return text unless color_enabled?
118
118
  "#{color_code}#{text}\e[0m"
119
119
  end
120
+
121
+ def bold(text)
122
+ color(text, "\e[1m")
123
+ end
124
+
125
+ def white(text)
126
+ color(text, "\e[37m")
127
+ end
120
128
 
121
129
  def green(text)
122
130
  color(text, "\e[32m")
@@ -124,22 +124,15 @@ module Micronaut
124
124
  # include CustomGameMatchers
125
125
  # ...
126
126
  # end
127
- #
128
- # or you can include in globally in a spec_helper.rb file <tt>require</tt>d
129
- # from your spec file(s):
130
- #
131
- # Micronaut::Runner.configure do |config|
132
- # config.include(CustomGameMatchers)
133
- # end
134
- #
127
+
135
128
  module Matchers
136
129
 
137
130
  class MatcherError < StandardError; end
138
131
 
139
132
  private
140
133
  def method_missing(sym, *args, &block) # :nodoc:
141
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
142
- return has(sym, *args) if sym.starts_with?("have_")
134
+ return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
135
+ return has(sym, *args) if sym.to_s =~ /^have_/
143
136
  super
144
137
  end
145
138
 
@@ -87,7 +87,7 @@ it reads really poorly.
87
87
  def parse_expected(expected)
88
88
  ["be_an_","be_a_","be_"].each do |prefix|
89
89
  handling_predicate!
90
- if expected.starts_with?(prefix)
90
+ if expected.to_s =~ /^#{prefix}/
91
91
  set_prefix(prefix)
92
92
  expected = expected.to_s.sub(prefix,"")
93
93
  [true, false, nil].each do |val|
@@ -1,5 +1,24 @@
1
1
  module Micronaut
2
2
  module Matchers
3
+
4
+ class BeClose
5
+ def initialize(expected, delta)
6
+ @expected, @delta = expected, delta
7
+ end
8
+
9
+ def matches?(actual)
10
+ @actual = actual
11
+ (@actual - @expected).abs < @delta
12
+ end
13
+
14
+ def failure_message
15
+ "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
16
+ end
17
+
18
+ def description
19
+ "be close to #{@expected} (within +- #{@delta})"
20
+ end
21
+ end
3
22
 
4
23
  # :call-seq:
5
24
  # should be_close(expected, delta)
@@ -11,12 +30,8 @@ module Micronaut
11
30
  #
12
31
  # result.should be_close(3.0, 0.5)
13
32
  def be_close(expected, delta)
14
- simple_matcher do |actual, matcher|
15
- matcher.failure_message = "expected #{expected} +/- (< #{delta}), got #{actual}"
16
- matcher.description = "be close to #{expected} (within +- #{delta})"
17
- (actual - expected).abs < delta
18
- end
33
+ BeClose.new(expected, delta)
19
34
  end
20
-
35
+
21
36
  end
22
- end
37
+ end
@@ -1,8 +1,8 @@
1
1
  module Micronaut
2
2
  module Matchers
3
3
  def method_missing(sym, *args, &block) # :nodoc:
4
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
5
- return has(sym, *args) if sym.starts_with?("have_")
4
+ return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
5
+ return has(sym, *args) if sym.to_s =~ /^have_/
6
6
  super
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spicycode-micronaut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.5
4
+ version: 0.2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries
@@ -9,7 +9,7 @@ autorequire: micronaut
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-20 00:00:00 -08:00
12
+ date: 2009-01-30 00:00:00 -08:00
13
13
  default_executable: micronaut
14
14
  dependencies: []
15
15
 
@@ -35,7 +35,6 @@ files:
35
35
  - lib/micronaut/expectations
36
36
  - lib/micronaut/expectations/extensions
37
37
  - lib/micronaut/expectations/extensions/object.rb
38
- - lib/micronaut/expectations/extensions/string_and_symbol.rb
39
38
  - lib/micronaut/expectations/handler.rb
40
39
  - lib/micronaut/expectations/wrap_expectation.rb
41
40
  - lib/micronaut/expectations.rb
@@ -96,7 +95,6 @@ files:
96
95
  - examples/lib/micronaut/matchers/description_generation_example.rb
97
96
  - examples/lib/micronaut/matchers/eql_example.rb
98
97
  - examples/lib/micronaut/matchers/equal_example.rb
99
- - examples/lib/micronaut/matchers/handler_example.rb
100
98
  - examples/lib/micronaut/matchers/has_example.rb
101
99
  - examples/lib/micronaut/matchers/have_example.rb
102
100
  - examples/lib/micronaut/matchers/include_example.rb
@@ -1,153 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
-
3
- module ExampleExpectations
4
-
5
- class ArbitraryMatcher
6
- def initialize(*args, &block)
7
- if args.last.is_a? Hash
8
- @expected = args.last[:expected]
9
- end
10
- if block_given?
11
- @expected = block.call
12
- end
13
- @block = block
14
- end
15
-
16
- def matches?(target)
17
- @target = target
18
- return @expected == target
19
- end
20
-
21
- def with(new_value)
22
- @expected = new_value
23
- self
24
- end
25
-
26
- def failure_message
27
- "expected #{@expected}, got #{@target}"
28
- end
29
-
30
- def negative_failure_message
31
- "expected not #{@expected}, got #{@target}"
32
- end
33
- end
34
-
35
- class PositiveOnlyMatcher < ArbitraryMatcher
36
- undef negative_failure_message rescue nil
37
- end
38
-
39
- def arbitrary_matcher(*args, &block)
40
- ArbitraryMatcher.new(*args, &block)
41
- end
42
-
43
- def positive_only_matcher(*args, &block)
44
- PositiveOnlyMatcher.new(*args, &block)
45
- end
46
-
47
- end
48
-
49
- describe Micronaut::Expectations::ExpectationMatcherHandler do
50
-
51
- describe "#handle_matcher" do
52
-
53
- it "should ask the matcher if it matches" do
54
- matcher = mock("matcher")
55
- actual = Object.new
56
- matcher.expects(:matches?).with(actual).returns(true)
57
- Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
58
- end
59
-
60
- it "should explain when the matcher parameter is not a matcher" do
61
- begin
62
- nonmatcher = mock("nonmatcher")
63
- actual = Object.new
64
- Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
65
- rescue Micronaut::Expectations::InvalidMatcherError => e
66
- end
67
-
68
- e.message.should =~ /^Expected a matcher, got /
69
- end
70
-
71
- it "should return the match value" do
72
- matcher = mock("matcher")
73
- actual = Object.new
74
- matcher.expects(:matches?).with(actual).returns(:this_value)
75
- Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
76
- end
77
-
78
- end
79
-
80
- end
81
-
82
- describe Micronaut::Expectations::NegativeExpectationMatcherHandler do
83
-
84
- describe "#handle_matcher" do
85
-
86
- it "should explain when matcher does not support should_not" do
87
- matcher = mock("matcher")
88
- matcher.stubs(:matches?)
89
- actual = Object.new
90
- lambda {
91
- Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
92
- }.should fail_with(/Matcher does not support should_not.\n/)
93
- end
94
-
95
- it "should ask the matcher if it matches" do
96
- matcher = mock("matcher")
97
- actual = Object.new
98
- matcher.stubs(:negative_failure_message)
99
- matcher.expects(:matches?).with(actual).returns(false)
100
- Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
101
- end
102
-
103
- it "should explain when the matcher parameter is not a matcher" do
104
- begin
105
- nonmatcher = mock("nonmatcher")
106
- actual = Object.new
107
- Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
108
- rescue Micronaut::Expectations::InvalidMatcherError => e
109
- end
110
-
111
- e.message.should =~ /^Expected a matcher, got /
112
- end
113
-
114
-
115
- it "should return the match value" do
116
- matcher = mock("matcher")
117
- actual = Object.new
118
- matcher.expects(:matches?).with(actual).returns(false)
119
- matcher.stubs(:negative_failure_message).returns("ignore")
120
- Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
121
- end
122
-
123
- end
124
-
125
- end
126
-
127
- describe Micronaut::Expectations::ExpectationMatcherHandler do
128
- include ExampleExpectations
129
-
130
- it "should handle submitted args" do
131
- 5.should arbitrary_matcher(:expected => 5)
132
- 5.should arbitrary_matcher(:expected => "wrong").with(5)
133
- lambda { 5.should arbitrary_matcher(:expected => 4) }.should fail_with("expected 4, got 5")
134
- lambda { 5.should arbitrary_matcher(:expected => 5).with(4) }.should fail_with("expected 4, got 5")
135
- 5.should_not arbitrary_matcher(:expected => 4)
136
- 5.should_not arbitrary_matcher(:expected => 5).with(4)
137
- lambda { 5.should_not arbitrary_matcher(:expected => 5) }.should fail_with("expected not 5, got 5")
138
- lambda { 5.should_not arbitrary_matcher(:expected => 4).with(5) }.should fail_with("expected not 5, got 5")
139
- end
140
-
141
- it "should handle the submitted block" do
142
- 5.should arbitrary_matcher { 5 }
143
- 5.should arbitrary_matcher(:expected => 4) { 5 }
144
- 5.should arbitrary_matcher(:expected => 4).with(5) { 3 }
145
- end
146
-
147
- it "should explain when matcher does not support should_not" do
148
- lambda {
149
- 5.should_not positive_only_matcher(:expected => 5)
150
- }.should fail_with(/Matcher does not support should_not.\n/)
151
- end
152
-
153
- end
@@ -1,19 +0,0 @@
1
- module Micronaut
2
- module Expectations
3
- module StringHelpers
4
-
5
- def starts_with?(prefix)
6
- to_s[0..(prefix.to_s.length - 1)] == prefix.to_s
7
- end
8
-
9
- end
10
- end
11
- end
12
-
13
- class String
14
- include Micronaut::Expectations::StringHelpers
15
- end
16
-
17
- class Symbol
18
- include Micronaut::Expectations::StringHelpers
19
- end