mocha 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.5.5 (r167)
2
+
3
+ - Renamed Matches parameter matcher to RegexpMatches for clarity.
4
+ - Added noframes tag to rdoc index to assist Google.
5
+
1
6
  = 0.5.4 (r166)
2
7
 
3
8
  - Added matches parameter matcher for matching regular expressions.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require 'rake/contrib/sshpublisher'
6
6
 
7
7
  module Mocha
8
- VERSION = "0.5.4"
8
+ VERSION = "0.5.5"
9
9
  end
10
10
 
11
11
  desc "Run all tests"
@@ -0,0 +1,40 @@
1
+ module Mocha
2
+
3
+ module ParameterMatchers
4
+
5
+ # :call-seq: regexp_matches(regexp) -> parameter_matcher
6
+ #
7
+ # Matches any object that matches the regular expression, +regexp+.
8
+ # object = mock()
9
+ # object.expects(:method_1).with(regexp_matches(/e/))
10
+ # object.method_1('hello')
11
+ # # no error raised
12
+ #
13
+ # object = mock()
14
+ # object.expects(:method_1).with(regexp_matches(/a/))
15
+ # object.method_1('hello')
16
+ # # error raised, because method_1 was not called with a parameter that matched the
17
+ # # regular expression
18
+ def regexp_matches(regexp)
19
+ RegexpMatches.new(regexp)
20
+ end
21
+
22
+ class RegexpMatches # :nodoc:
23
+
24
+ def initialize(regexp)
25
+ @regexp = regexp
26
+ end
27
+
28
+ def ==(parameter)
29
+ parameter =~ @regexp
30
+ end
31
+
32
+ def mocha_inspect
33
+ "regexp_matches(#{@regexp.mocha_inspect})"
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -60,4 +60,22 @@ class ParameterMatcherAcceptanceTest < Test::Unit::TestCase
60
60
  assert_failed(test_result)
61
61
  end
62
62
 
63
+ def test_should_match_parameter_that_matches_regular_expression
64
+ test_result = run_test do
65
+ mock = mock()
66
+ mock.expects(:method).with(regexp_matches(/meter/))
67
+ mock.method('this parameter should match')
68
+ end
69
+ assert_passed(test_result)
70
+ end
71
+
72
+ def test_should_not_match_parameter_that_does_not_match_regular_expression
73
+ test_result = run_test do
74
+ mock = mock()
75
+ mock.expects(:method).with(regexp_matches(/something different/))
76
+ mock.method('this parameter should not match')
77
+ end
78
+ assert_failed(test_result)
79
+ end
80
+
63
81
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
2
2
 
3
- require 'mocha/parameter_matchers/matches'
3
+ require 'mocha/parameter_matchers/regexp_matches'
4
4
  require 'mocha/inspect'
5
5
 
6
6
  class MatchesTest < Test::Unit::TestCase
@@ -8,18 +8,18 @@ class MatchesTest < Test::Unit::TestCase
8
8
  include Mocha::ParameterMatchers
9
9
 
10
10
  def test_should_match_parameter_matching_regular_expression
11
- matcher = matches(/oo/)
11
+ matcher = regexp_matches(/oo/)
12
12
  assert matcher == 'foo'
13
13
  end
14
14
 
15
15
  def test_should_not_match_parameter_not_matching_regular_expression
16
- matcher = matches(/oo/)
16
+ matcher = regexp_matches(/oo/)
17
17
  assert matcher != 'bar'
18
18
  end
19
19
 
20
20
  def test_should_describe_matcher
21
- matcher = matches(/oo/)
22
- assert_equal "matches(/oo/)", matcher.mocha_inspect
21
+ matcher = regexp_matches(/oo/)
22
+ assert_equal "regexp_matches(/oo/)", matcher.mocha_inspect
23
23
  end
24
24
 
25
25
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: mocha
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.4
7
- date: 2007-08-28 00:00:00 +01:00
6
+ version: 0.5.5
7
+ date: 2007-09-06 00:00:00 +01:00
8
8
  summary: Mocking and stubbing library
9
9
  require_paths:
10
10
  - lib
@@ -57,7 +57,7 @@ files:
57
57
  - lib/mocha/parameter_matchers/includes.rb
58
58
  - lib/mocha/parameter_matchers/instance_of.rb
59
59
  - lib/mocha/parameter_matchers/kind_of.rb
60
- - lib/mocha/parameter_matchers/matches.rb
60
+ - lib/mocha/parameter_matchers/regexp_matches.rb
61
61
  - lib/mocha/parameter_matchers.rb
62
62
  - lib/mocha/pretty_parameters.rb
63
63
  - lib/mocha/return_values.rb
@@ -113,7 +113,7 @@ files:
113
113
  - test/unit/parameter_matchers/includes_test.rb
114
114
  - test/unit/parameter_matchers/instance_of_test.rb
115
115
  - test/unit/parameter_matchers/kind_of_test.rb
116
- - test/unit/parameter_matchers/matches_test.rb
116
+ - test/unit/parameter_matchers/regexp_matches_test.rb
117
117
  - test/unit/parameter_matchers/stub_matcher.rb
118
118
  - test/unit/pretty_parameters_test.rb
119
119
  - test/unit/return_values_test.rb
@@ -1,39 +0,0 @@
1
- module Mocha
2
-
3
- module ParameterMatchers
4
-
5
- # :call-seq: matches(regular_expression) -> parameter_matcher
6
- #
7
- # Matches any object matching +regular_expression+.
8
- # object = mock()
9
- # object.expects(:method_1).with(matches(/oo/))
10
- # object.method_1('foo')
11
- # # no error raised
12
- #
13
- # object = mock()
14
- # object.expects(:method_1).with(matches(/oo/))
15
- # object.method_1('bar')
16
- # # error raised, because method_1 was not called with parameter matching regular expression: /oo/
17
- def matches(regular_expression)
18
- Matches.new(regular_expression)
19
- end
20
-
21
- class Matches # :nodoc:
22
-
23
- def initialize(regular_expression)
24
- @regular_expression = regular_expression
25
- end
26
-
27
- def ==(parameter)
28
- @regular_expression.match(parameter)
29
- end
30
-
31
- def mocha_inspect
32
- "matches(#{@regular_expression.mocha_inspect})"
33
- end
34
-
35
- end
36
-
37
- end
38
-
39
- end