flexmock 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #---
4
+ # Copyright 2003-2012 by Jim Weirich (jim.weirich@gmail.com).
5
+ # All rights reserved.
6
+
7
+ # Permission is granted for use, copying, modification, distribution,
8
+ # and distribution of modified versions of this work as long as the
9
+ # above copyright notice is included.
10
+ #+++
11
+
12
+ require 'test/test_setup'
13
+
14
+ class BasedPartialsTest < Test::Unit::TestCase
15
+ include FlexMock::TestCase
16
+
17
+ def setup
18
+ super
19
+ FlexMock.partials_are_based = true
20
+ end
21
+
22
+ def teardown
23
+ FlexMock.partials_are_based = false
24
+ super
25
+ end
26
+
27
+ class Dog
28
+ def bark
29
+ :woof
30
+ end
31
+ end
32
+
33
+ def test_based_partials_allow_stubbing_defined_methods
34
+ dog = Dog.new
35
+ flexmock(dog).should_receive(:bark => :mock_value)
36
+ assert_equal :mock_value, dog.bark
37
+ end
38
+
39
+ def test_based_partials_disallow_stubbing_undefined_methods
40
+ dog = Dog.new
41
+ assert_raise(NoMethodError, /cannot stub.*wag.*explicitly/) do
42
+ flexmock(dog).should_receive(:wag => :mock_value)
43
+ end
44
+ end
45
+
46
+ def test_based_partials_allow_explicitly_stubbing_undefined_methods
47
+ dog = Dog.new
48
+ flexmock(dog).should_receive(:wag).explicitly.and_return(:mock_value)
49
+ end
50
+
51
+ end
@@ -18,15 +18,15 @@ class TestFlexmockDefaultFrameworkAdapter < Test::Unit::TestCase
18
18
 
19
19
  def test_assert_block_raises_exception
20
20
  assert_raise(FlexMock::DefaultFrameworkAdapter::AssertionFailedError) {
21
- @adapter.assert_block("failure message") { false }
21
+ @adapter.make_assertion("failure message") { false }
22
22
  }
23
23
  end
24
24
 
25
- def test_assert_block_doesnt_raise_exception
26
- @adapter.assert_block("failure message") { true }
25
+ def test_make_assertion_doesnt_raise_exception
26
+ @adapter.make_assertion("failure message") { true }
27
27
  end
28
28
 
29
- def test_assert_equal_doesnt_raise_exception
29
+ def test_make_assertion_doesnt_raise_exception
30
30
  @adapter.assert_equal("a", "a", "no message")
31
31
  end
32
32
 
@@ -400,6 +400,21 @@ class TestStubbing < Test::Unit::TestCase
400
400
  assert_equal :hiss, dog.meow
401
401
  end
402
402
 
403
+ def test_partial_mocks_allow_stubbing_defined_methods_when_using_on
404
+ dog = Dog.new
405
+ flexmock(dog, :on, Dog)
406
+ dog.should_receive(:bark).and_return(:grrr)
407
+ assert_equal :grrr, dog.bark
408
+ end
409
+
410
+ def test_partial_mocks_disallow_stubbing_undefined_methods_when_using_on
411
+ dog = Dog.new
412
+ flexmock(dog, :on, Dog)
413
+ assert_raise(NoMethodError, /meow.*explicitly/) do
414
+ dog.should_receive(:meow).and_return(:something)
415
+ end
416
+ end
417
+
403
418
  # The following test was suggested by Pat Maddox for the RSpec
404
419
  # mocks. Evidently the (poorly implemented) == method caused issues
405
420
  # with RSpec Mock's internals. I'm just double checking for any
@@ -93,7 +93,7 @@ class TestSpys < Test::Unit::TestCase
93
93
  def test_spy_accepts_correct_additional_validations
94
94
  @spy.foo(2)
95
95
  is_even = proc { |n| assert_equal 0, n%2 }
96
- assert_spy_called @spy, { and: is_even }, :foo, Integer
96
+ assert_spy_called @spy, { :and => is_even }, :foo, Integer
97
97
  end
98
98
 
99
99
  def test_spy_accepts_multiple_additional_validations_first_failing
@@ -101,7 +101,7 @@ class TestSpys < Test::Unit::TestCase
101
101
  is_two = proc { |n| assert_equal 2, n }
102
102
  is_even = proc { |n| assert_equal 0, n%2 }
103
103
  assert_failed(/2.*expected but was.*4/mi) do
104
- assert_spy_called @spy, { and: [is_two, is_even] }, :foo, Integer
104
+ assert_spy_called @spy, { :and => [is_two, is_even] }, :foo, Integer
105
105
  end
106
106
  end
107
107
 
@@ -110,7 +110,7 @@ class TestSpys < Test::Unit::TestCase
110
110
  is_even = proc { |n| assert_equal 0, n%2 }
111
111
  is_two = proc { |n| assert_equal 2, n }
112
112
  assert_failed(/2.*expected but was.*4/mi) do
113
- assert_spy_called @spy, { and: [is_even, is_two] }, :foo, Integer
113
+ assert_spy_called @spy, { :and => [is_even, is_two] }, :foo, Integer
114
114
  end
115
115
  end
116
116
 
@@ -118,7 +118,7 @@ class TestSpys < Test::Unit::TestCase
118
118
  @spy.foo(3)
119
119
  is_even = proc { |n| assert_equal 0, n%2 }
120
120
  assert_failed(/0.*expected but was.*1/mi) do
121
- assert_spy_called @spy, { and: is_even }, :foo, Integer
121
+ assert_spy_called @spy, { :and => is_even }, :foo, Integer
122
122
  end
123
123
  end
124
124
 
@@ -128,7 +128,7 @@ class TestSpys < Test::Unit::TestCase
128
128
  @spy.foo(4)
129
129
  is_even = proc { |n| assert_equal 0, n%2 }
130
130
  assert_failed(/0.*expected but was.*1/mi) do
131
- assert_spy_called @spy, { and: is_even, on: 2 }, :foo, Integer
131
+ assert_spy_called @spy, { :and => is_even, :on => 2 }, :foo, Integer
132
132
  end
133
133
  end
134
134
 
@@ -136,11 +136,11 @@ class TestSpys < Test::Unit::TestCase
136
136
  failed = false
137
137
  begin
138
138
  yield
139
- rescue MiniTest::Assertion => ex
139
+ rescue assertion_failed_error => ex
140
140
  failed = true
141
141
  assert_match message_pattern, ex.message
142
142
  end
143
- refute(!failed, "Expected block to fail")
143
+ assert(failed, "Expected block to fail")
144
144
  end
145
145
 
146
146
  def test_spy_methods_can_be_stubbed
@@ -15,7 +15,6 @@ class FlexMock
15
15
  # expected error message.
16
16
  def assert_failure(options={}, &block)
17
17
  message = options[:message]
18
- no_location = options[:no_location]
19
18
  ex = assert_raises(assertion_failed_error) { yield }
20
19
  if message
21
20
  case message
@@ -54,9 +53,10 @@ class FlexMock
54
53
  loc_re = Regexp.compile(Regexp.quote(file))
55
54
  end
56
55
 
56
+
57
57
  if search_all
58
58
  bts = ex.backtrace.join("\n")
59
- assert_block("expected a backtrace line to match #{loc_re}\nBACKTRACE:\n#{bts}") {
59
+ assert_with_block("expected a backtrace line to match #{loc_re}\nBACKTRACE:\n#{bts}") {
60
60
  ex.backtrace.any? { |bt| loc_re =~ bt }
61
61
  }
62
62
  else
@@ -65,5 +65,11 @@ class FlexMock
65
65
 
66
66
  ex
67
67
  end
68
+
69
+ def assert_with_block(msg=nil)
70
+ unless yield
71
+ assert(false, msg || "Expected block to yield true")
72
+ end
73
+ end
68
74
  end
69
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "\n FlexMock is a extremely simple mock object class compatible\n
15
15
  \ with the Test::Unit framework. Although the FlexMock's\n interface is
@@ -21,6 +21,8 @@ extra_rdoc_files:
21
21
  - doc/index.rdoc
22
22
  - CHANGES
23
23
  - doc/GoogleExample.rdoc
24
+ - doc/examples/rspec_examples_spec.rdoc
25
+ - doc/examples/test_unit_examples_test.rdoc
24
26
  - doc/releases/flexmock-0.4.0.rdoc
25
27
  - doc/releases/flexmock-0.4.1.rdoc
26
28
  - doc/releases/flexmock-0.4.2.rdoc
@@ -46,15 +48,15 @@ extra_rdoc_files:
46
48
  - doc/releases/flexmock-1.1.0.rdoc
47
49
  - doc/releases/flexmock-1.2.0.rdoc
48
50
  - doc/releases/flexmock-1.3.0.rdoc
49
- - doc/examples/rspec_examples_spec.rdoc
50
- - doc/examples/test_unit_examples_test.rdoc
51
+ - doc/releases/flexmock-1.3.1.rdoc
51
52
  files:
52
53
  - CHANGES
53
54
  - Gemfile
54
55
  - Gemfile.lock
55
- - Rakefile
56
56
  - README.md
57
+ - Rakefile
57
58
  - TAGS
59
+ - lib/flexmock.rb
58
60
  - lib/flexmock/argument_matchers.rb
59
61
  - lib/flexmock/argument_matching.rb
60
62
  - lib/flexmock/argument_types.rb
@@ -74,11 +76,11 @@ files:
74
76
  - lib/flexmock/object_extensions.rb
75
77
  - lib/flexmock/ordering.rb
76
78
  - lib/flexmock/partial_mock.rb
77
- - lib/flexmock/rails/view_mocking.rb
78
79
  - lib/flexmock/rails.rb
80
+ - lib/flexmock/rails/view_mocking.rb
79
81
  - lib/flexmock/recorder.rb
80
- - lib/flexmock/rspec/configure.rb
81
82
  - lib/flexmock/rspec.rb
83
+ - lib/flexmock/rspec/configure.rb
82
84
  - lib/flexmock/rspec_spy_matcher.rb
83
85
  - lib/flexmock/spy_describers.rb
84
86
  - lib/flexmock/symbol_extensions.rb
@@ -88,10 +90,10 @@ files:
88
90
  - lib/flexmock/undefined.rb
89
91
  - lib/flexmock/validators.rb
90
92
  - lib/flexmock/version.rb
91
- - lib/flexmock.rb
92
93
  - test/aliasing_test.rb
93
94
  - test/assert_spy_called_test.rb
94
95
  - test/base_class_test.rb
96
+ - test/based_partials_test.rb
95
97
  - test/container_methods_test.rb
96
98
  - test/default_framework_adapter_test.rb
97
99
  - test/demeter_mocking_test.rb
@@ -123,6 +125,8 @@ files:
123
125
  - install.rb
124
126
  - doc/index.rdoc
125
127
  - doc/GoogleExample.rdoc
128
+ - doc/examples/rspec_examples_spec.rdoc
129
+ - doc/examples/test_unit_examples_test.rdoc
126
130
  - doc/releases/flexmock-0.4.0.rdoc
127
131
  - doc/releases/flexmock-0.4.1.rdoc
128
132
  - doc/releases/flexmock-0.4.2.rdoc
@@ -148,8 +152,7 @@ files:
148
152
  - doc/releases/flexmock-1.1.0.rdoc
149
153
  - doc/releases/flexmock-1.2.0.rdoc
150
154
  - doc/releases/flexmock-1.3.0.rdoc
151
- - doc/examples/rspec_examples_spec.rdoc
152
- - doc/examples/test_unit_examples_test.rdoc
155
+ - doc/releases/flexmock-1.3.1.rdoc
153
156
  homepage: https://github.com/jimweirich/flexmock
154
157
  licenses: []
155
158
  post_install_message:
@@ -167,9 +170,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
170
  - - ! '>='
168
171
  - !ruby/object:Gem::Version
169
172
  version: '0'
170
- segments:
171
- - 0
172
- hash: -2506978520909989178
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  none: false
175
175
  requirements: