flexmock 1.3.3 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +3 -0
  3. data/.gitignore +14 -0
  4. data/.togglerc +7 -0
  5. data/.travis.yml +5 -0
  6. data/.yardopts +2 -0
  7. data/CHANGES +11 -0
  8. data/Gemfile +1 -4
  9. data/README.md +39 -11
  10. data/Rakefile +6 -217
  11. data/doc/examples/rspec_examples_spec.rb +244 -0
  12. data/doc/examples/test_unit_examples_test.rb +240 -0
  13. data/doc/jamis.rb +591 -0
  14. data/flexmock.gemspec +33 -0
  15. data/lib/flexmock.rb +0 -1
  16. data/lib/flexmock/composite_expectation.rb +1 -1
  17. data/lib/flexmock/core.rb +3 -7
  18. data/lib/flexmock/core_class_methods.rb +5 -1
  19. data/lib/flexmock/default_framework_adapter.rb +2 -2
  20. data/lib/flexmock/expectation.rb +29 -3
  21. data/lib/flexmock/expectation_director.rb +1 -1
  22. data/lib/flexmock/minitest.rb +13 -0
  23. data/lib/flexmock/minitest_extensions.rb +26 -0
  24. data/lib/flexmock/minitest_integration.rb +111 -0
  25. data/lib/flexmock/mock_container.rb +1 -2
  26. data/lib/flexmock/partial_mock.rb +61 -104
  27. data/lib/flexmock/recorder.rb +1 -2
  28. data/lib/flexmock/rspec.rb +6 -3
  29. data/lib/flexmock/test_unit_integration.rb +14 -0
  30. data/lib/flexmock/validators.rb +5 -4
  31. data/lib/flexmock/version.rb +1 -9
  32. data/rakelib/metrics.rake +40 -0
  33. data/rakelib/preview.rake +4 -0
  34. data/rakelib/tags.rake +18 -0
  35. data/todo.txt +20 -0
  36. metadata +61 -86
  37. data/Gemfile.lock +0 -20
  38. data/doc/examples/rspec_examples_spec.rdoc +0 -245
  39. data/doc/examples/test_unit_examples_test.rdoc +0 -241
  40. data/test/aliasing_test.rb +0 -66
  41. data/test/assert_spy_called_test.rb +0 -119
  42. data/test/base_class_test.rb +0 -71
  43. data/test/based_partials_test.rb +0 -51
  44. data/test/container_methods_test.rb +0 -118
  45. data/test/default_framework_adapter_test.rb +0 -38
  46. data/test/demeter_mocking_test.rb +0 -191
  47. data/test/deprecated_methods_test.rb +0 -225
  48. data/test/examples_from_readme_test.rb +0 -157
  49. data/test/expectation_description_test.rb +0 -80
  50. data/test/extended_should_receive_test.rb +0 -69
  51. data/test/flexmodel_test.rb +0 -54
  52. data/test/mock_builder_test.rb +0 -68
  53. data/test/naming_test.rb +0 -84
  54. data/test/new_instances_test.rb +0 -215
  55. data/test/object_extensions_test.rb +0 -25
  56. data/test/partial_mock_test.rb +0 -458
  57. data/test/record_mode_test.rb +0 -158
  58. data/test/redirect_error.rb +0 -16
  59. data/test/rspec_integration/integration_spec.rb +0 -56
  60. data/test/rspec_integration/spy_example_spec.rb +0 -207
  61. data/test/samples_test.rb +0 -283
  62. data/test/should_ignore_missing_test.rb +0 -84
  63. data/test/should_receive_test.rb +0 -1155
  64. data/test/spys_test.rb +0 -215
  65. data/test/symbol_extensions_test.rb +0 -8
  66. data/test/test_class_extensions.rb +0 -34
  67. data/test/test_setup.rb +0 -92
  68. data/test/test_unit_integration/auto_test_unit_test.rb +0 -42
  69. data/test/test_unit_integration/minitest_teardown_test.rb +0 -14
  70. data/test/tu_integration_test.rb +0 -99
  71. data/test/undefined_test.rb +0 -87
@@ -1,157 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 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 TemperatureSampler
15
- def initialize(sensor)
16
- @sensor = sensor
17
- end
18
-
19
- def average_temp
20
- total = (0...3).collect { @sensor.read_temperature }.inject { |i, s| i + s }
21
- total / 3.0
22
- end
23
- end
24
-
25
- class TestTemperatureSampler < Test::Unit::TestCase
26
- include FlexMock::TestCase
27
-
28
- def test_tempurature_sampler
29
- readings = [10, 12, 14]
30
- mock_sensor = flexmock("sensor")
31
- mock_sensor.should_receive(:read_temperature).and_return { readings.shift }
32
- sampler = TemperatureSampler.new(mock_sensor)
33
- assert_equal 12, sampler.average_temp
34
- end
35
- end
36
-
37
- class TestExamplesFromReadme < Test::Unit::TestCase
38
- include FlexMock::TestCase
39
-
40
- def test_simple_return_values
41
- m = flexmock(:pi => 3.1416, :e => 2.71)
42
- assert_equal 3.1416, m.pi
43
- assert_equal 2.71, m.e
44
- end
45
-
46
- def test_returning_an_undefined_value
47
- m = flexmock("mock")
48
- m.should_receive(:foo).and_return_undefined
49
- m.foo.bar.baz
50
- end
51
-
52
- def test_db
53
- db = flexmock('db')
54
- db.should_receive(:query).and_return([1,2,3])
55
- db.should_receive(:update).with(5).and_return(nil).once
56
- # test code here
57
- assert_equal [1, 2, 3], db.query
58
- db.update(5)
59
- end
60
-
61
- def test_query_and_update
62
- db = flexmock('db')
63
- db.should_receive(:query).and_return([1,2,3]).ordered
64
- db.should_receive(:update).and_return(nil).ordered
65
- # test code here
66
- assert_equal [1,2,3], db.query
67
- assert_nil db.update
68
- end
69
-
70
- def test_ordered_queries
71
- db = flexmock('db')
72
- db.should_receive(:startup).once.ordered
73
- db.should_receive(:query).with("GOOG").and_return(12.3).
74
- once.ordered(:queries)
75
- db.should_receive(:query).with("APPL").and_return(10.0).
76
- once.ordered(:queries)
77
- db.should_receive(:query).with(/^....$/).and_return(3.3).
78
- at_least.once.ordered(:queries)
79
- db.should_receive(:finish).once.ordered
80
- # test code here
81
- db.startup
82
- assert_equal 3.3, db.query("WXYZ")
83
- assert_equal 10.0, db.query("APPL")
84
- assert_equal 12.3, db.query("GOOG")
85
- db.finish
86
- end
87
-
88
- def test_ordered_queries_in_record_mode
89
- db = flexmock('db')
90
- db.should_expect do |rec|
91
- rec.startup.once.ordered
92
- rec.query("GOOG") { 12.3 }.once.ordered(:queries)
93
- rec.query("APPL") { 10.0 }.once.ordered(:queries)
94
- rec.query(/^....$/) { 3.3 }.at_least.once.ordered(:queries)
95
- rec.finish.once.ordered
96
- end
97
- # test code here using +db+.
98
- db.startup
99
- assert_equal 10.0, db.query("APPL")
100
- assert_equal 12.3, db.query("GOOG")
101
- assert_equal 3.3, db.query("WXYZ")
102
- db.finish
103
- end
104
-
105
- def test_build_xml
106
- builder = flexmock('builder')
107
- builder.should_expect do |rec|
108
- rec.should_be_strict
109
- known_good_way_to_build_xml(rec) # record the messages
110
- end
111
- new_way_to_build_xml(builder) # compare to new way
112
- end
113
-
114
- def known_good_way_to_build_xml(rec)
115
- rec.one
116
- rec.two
117
- end
118
-
119
- def new_way_to_build_xml(rec)
120
- [:one, :two].each do |sym| rec.send(sym) end
121
- end
122
-
123
- def test_multiple_gets
124
- file = flexmock('file')
125
- file.should_receive(:gets).with_no_args.
126
- and_return("line 1\n", "line 2\n")
127
- # test code here
128
- assert_equal "line 1\n", file.gets
129
- assert_equal "line 2\n", file.gets
130
- end
131
-
132
- def test_an_important_message
133
- m = flexmock('m')
134
- m.should_receive(:an_important_message).and_return(1).once
135
- m.should_ignore_missing
136
- # test code here
137
- m.an_important_message
138
- m.unknown_message.bar.baz
139
- end
140
-
141
- class QuoteService
142
- end
143
- class Portfolio
144
- def value
145
- QuoteService.new.quote
146
- end
147
- end
148
-
149
- def test_portfolio_value
150
- flexmock(QuoteService).new_instances do |m|
151
- m.should_receive(:quote).and_return(100)
152
- end
153
- port = Portfolio.new
154
- value = port.value # Portfolio calls QuoteService.quote
155
- assert_equal 100, value
156
- end
157
- end
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 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 ExpectationDescriptionTest < Test::Unit::TestCase
15
- include FlexMock::TestCase
16
-
17
- def setup
18
- @mock = flexmock("mock")
19
- @exp = FlexMock::Expectation.new(@mock, :foo, "file.rb:3")
20
- end
21
-
22
- def test_basic_description
23
- assert_equal "should_receive(:foo)", @exp.description
24
- end
25
-
26
- def test_with_no_args
27
- @exp.with()
28
- assert_equal "should_receive(:foo).with()", @exp.description
29
- end
30
-
31
- def test_with_simple_args
32
- @exp.with(1, "HI")
33
- assert_equal "should_receive(:foo).with(1, \"HI\")", @exp.description
34
- end
35
-
36
- def test_with_never
37
- @exp.never
38
- assert_equal "should_receive(:foo).never", @exp.description
39
- end
40
-
41
- def test_with_once
42
- @exp.once
43
- assert_equal "should_receive(:foo).once", @exp.description
44
- end
45
-
46
- def test_with_twice
47
- @exp.twice
48
- assert_equal "should_receive(:foo).twice", @exp.description
49
- end
50
-
51
- def test_with_3
52
- @exp.times(3)
53
- assert_equal "should_receive(:foo).times(3)", @exp.description
54
- end
55
-
56
- def test_with_at_least_once
57
- @exp.at_least.once
58
- assert_equal "should_receive(:foo).at_least.once", @exp.description
59
- end
60
-
61
- def test_with_at_least_10
62
- @exp.at_least.times(10)
63
- assert_equal "should_receive(:foo).at_least.times(10)", @exp.description
64
- end
65
-
66
- def test_with_at_most_once
67
- @exp.at_most.once
68
- assert_equal "should_receive(:foo).at_most.once", @exp.description
69
- end
70
-
71
- def test_with_zero_or_more_times
72
- @exp.at_most.zero_or_more_times
73
- assert_equal "should_receive(:foo).zero_or_more_times", @exp.description
74
- end
75
-
76
- def test_with_at_least_1_at_most_10
77
- @exp.at_least.once.at_most.times(10)
78
- assert_equal "should_receive(:foo).at_least.once.at_most.times(10)", @exp.description
79
- end
80
- end
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 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
- module ExtendedShouldReceiveTests
15
- def test_accepts_expectation_hash
16
- @mock.should_receive( :foo => :bar, :baz => :froz )
17
- assert_equal :bar, @obj.foo
18
- assert_equal :froz, @obj.baz
19
- end
20
-
21
- def test_accepts_list_of_methods
22
- @mock.should_receive(:foo, :bar, "baz")
23
- assert_nil @obj.foo
24
- assert_nil @obj.bar
25
- assert_nil @obj.baz
26
- end
27
-
28
- def test_contraints_apply_to_all_expectations
29
- @mock.should_receive(:foo, :bar => :baz).with(1)
30
- ex = assert_raise(assertion_failed_error) { @obj.foo(2) }
31
- ex = assert_raise(assertion_failed_error) { @obj.bar(2) }
32
- assert_equal :baz, @obj.bar(1)
33
- end
34
-
35
- def test_count_contraints_apply_to_all_expectations
36
- @mock.should_receive(:foo, :bar => :baz).once
37
- @obj.foo
38
- assert_raise(assertion_failed_error) { @mock.flexmock_verify }
39
- end
40
-
41
- def test_multiple_should_receives_are_allowed
42
- @mock.should_receive(:hi).and_return(:bye).
43
- should_receive(:hello => :goodbye)
44
- assert_equal :bye, @obj.hi
45
- assert_equal :goodbye, @obj.hello
46
- end
47
- end
48
-
49
- class TestExtendedShouldReceiveOnFullMocks < Test::Unit::TestCase
50
- include FlexMock::TestCase
51
- include ExtendedShouldReceiveTests
52
-
53
- def setup
54
- @mock = flexmock("mock")
55
- @obj = @mock
56
- end
57
-
58
- end
59
-
60
- class TestExtendedShouldReceiveOnPartialMockProxies < Test::Unit::TestCase
61
- include FlexMock::TestCase
62
- include ExtendedShouldReceiveTests
63
-
64
- def setup
65
- @obj = Object.new
66
- @mock = flexmock(@obj, "mock")
67
- end
68
-
69
- end
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/test_setup'
4
-
5
- class DummyModel
6
- end
7
-
8
- class ChildModel < DummyModel
9
- end
10
-
11
- ######################################################################
12
- class TestFlexModel < Test::Unit::TestCase
13
- include FlexMock::TestCase
14
-
15
- def test_initial_conditions
16
- model = flexmock(:model, DummyModel)
17
- assert_match(/^DummyModel_\d+/, model.flexmock_name)
18
- assert_equal model.id.to_s, model.to_params
19
- assert ! model.new_record?
20
- assert model.is_a?(DummyModel)
21
- # TODO: Make these work!!!
22
- assert_equal DummyModel, model.class
23
- assert model.instance_of?(DummyModel)
24
- assert model.kind_of?(DummyModel)
25
- end
26
-
27
- def test_classifying_mock_models
28
- model = flexmock(:model, ChildModel)
29
-
30
- assert model.kind_of?(ChildModel)
31
- assert model.instance_of?(ChildModel)
32
-
33
- assert model.kind_of?(DummyModel)
34
- assert ! model.instance_of?(DummyModel)
35
- end
36
-
37
- def test_mock_models_have_different_ids
38
- m1 = flexmock(:model, DummyModel)
39
- m2 = flexmock(:model, DummyModel)
40
- assert m2.id != m1.id
41
- end
42
-
43
- def test_mock_models_can_have_quick_defs
44
- model = flexmock(:model, DummyModel, :xyzzy => :ok)
45
- assert_equal :ok, model.xyzzy
46
- end
47
-
48
- def test_mock_models_can_have_blocks
49
- model = flexmock(:model, DummyModel) do |m|
50
- m.should_receive(:xyzzy => :okdokay)
51
- end
52
- assert_equal :okdokay, model.xyzzy
53
- end
54
- end
@@ -1,68 +0,0 @@
1
- require 'test/test_setup'
2
-
3
- class MockBuilderTest < Test::Unit::TestCase
4
- include FlexMock::TestCase
5
-
6
- def assert_method_name(name)
7
- assert_match(FlexMock::ExpectationBuilder::METHOD_NAME_RE, name)
8
- end
9
-
10
- def assert_not_method_name(name)
11
- refute_match(FlexMock::ExpectationBuilder::METHOD_NAME_RE, name)
12
- end
13
-
14
- def test_valid_method_names
15
- assert_method_name "foo"
16
- assert_method_name "FooBar"
17
- assert_method_name "_foo"
18
- assert_method_name "__foo"
19
- assert_method_name "___foo"
20
- assert_method_name "_"
21
- assert_method_name "foo_bar"
22
- assert_method_name "foo__bar"
23
- assert_method_name "foo_bar_"
24
- assert_method_name "foo12"
25
- assert_method_name "foo_bar_12"
26
- assert_method_name "foo?"
27
- assert_method_name "foo!"
28
- assert_method_name "foo="
29
- assert_method_name "+"
30
- assert_method_name "-"
31
- assert_method_name "*"
32
- assert_method_name "/"
33
- assert_method_name "&"
34
- assert_method_name "|"
35
- assert_method_name "^"
36
- assert_method_name "~"
37
- assert_method_name "=~"
38
- assert_method_name "!~"
39
- assert_method_name "`"
40
- assert_method_name "!"
41
- assert_method_name "**"
42
- assert_method_name "+@"
43
- assert_method_name "-@"
44
- assert_method_name "=="
45
- assert_method_name "!="
46
- assert_method_name "==="
47
- assert_method_name "<="
48
- assert_method_name ">="
49
- assert_method_name "<"
50
- assert_method_name ">"
51
- assert_method_name "<=>"
52
- assert_method_name "[]"
53
- assert_method_name "[]="
54
- end
55
-
56
- def test_invalid_method_names
57
- assert_not_method_name ""
58
- assert_not_method_name "1"
59
- assert_not_method_name "1foo"
60
- assert_not_method_name "foo!!"
61
- assert_not_method_name "foo!?"
62
- assert_not_method_name "foo?="
63
- assert_not_method_name "foo@"
64
- assert_not_method_name "++"
65
- assert_not_method_name "!!"
66
- assert_not_method_name "~="
67
- end
68
- end
data/test/naming_test.rb DELETED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #---
4
- # Copyright 2003-2013 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 TestNaming < Test::Unit::TestCase
15
- include FlexMock::TestCase
16
-
17
- def test_name
18
- m = flexmock("m")
19
- assert_equal "m", m.flexmock_name
20
- end
21
-
22
- def test_name_in_no_handler_found_error
23
- m = flexmock("mmm")
24
- ex = assert_raises(assertion_failed_error) {
25
- m.should_receive(:xx).with(1)
26
- m.xx(2)
27
- }
28
- assert_match(/'mmm'/, ex.message)
29
- end
30
-
31
- def test_name_in_received_count_error
32
- m = flexmock("mmm")
33
- ex = assert_raises(assertion_failed_error) {
34
- m.should_receive(:xx).once
35
- m.flexmock_verify
36
- }
37
- assert_match(/'mmm'/, ex.message)
38
- end
39
-
40
- def test_naming_with_use
41
- FlexMock.use("blah") do |m|
42
- assert_equal "blah", m.flexmock_name
43
- end
44
- end
45
-
46
- def test_naming_with_multiple_mocks_in_use
47
- FlexMock.use("blah", "yuk") do |a, b|
48
- assert_equal "blah", a.flexmock_name
49
- assert_equal "yuk", b.flexmock_name
50
- end
51
- end
52
-
53
- def test_inspect_returns_reasonable_name
54
- FlexMock.use("XYZZY") do |m|
55
- assert_equal "XYZZY", m.flexmock_name
56
- assert_equal "<FlexMock:XYZZY>", m.inspect
57
- end
58
- end
59
-
60
- def test_mock_can_override_inspect
61
- FlexMock.use("XYZZY") do |m|
62
- m.should_receive(:inspect).with_no_args.and_return("MOCK-INSPECT")
63
- assert_equal "MOCK-INSPECT", m.inspect
64
- end
65
- end
66
-
67
- class Dummy
68
- def inspect
69
- "DUMMY-INSPECT"
70
- end
71
- end
72
-
73
- def test_partial_mocks_use_original_inspect
74
- dummy = Dummy.new
75
- flexmock(dummy).should_receive(:msg)
76
- assert_equal "DUMMY-INSPECT", dummy.inspect
77
- end
78
-
79
- def test_partial_mocks_can_override_inspect
80
- dummy = Dummy.new
81
- flexmock(dummy).should_receive(:inspect).and_return("MOCK-INSPECT")
82
- assert_equal "MOCK-INSPECT", dummy.inspect
83
- end
84
- end