flexmock 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +9 -9
- data/Rakefile +3 -1
- data/lib/flexmock.rb +1 -1
- data/lib/flexmock/argument_matchers.rb +1 -1
- data/lib/flexmock/argument_types.rb +1 -2
- data/lib/flexmock/base.rb +2 -1
- data/lib/flexmock/call_record.rb +30 -0
- data/lib/flexmock/call_validator.rb +68 -0
- data/lib/flexmock/composite_expectation.rb +56 -0
- data/lib/flexmock/core.rb +30 -64
- data/lib/flexmock/core_class_methods.rb +1 -1
- data/lib/flexmock/default_framework_adapter.rb +1 -1
- data/lib/flexmock/deprecated_methods.rb +8 -3
- data/lib/flexmock/errors.rb +1 -1
- data/lib/flexmock/expectation.rb +7 -84
- data/lib/flexmock/expectation_builder.rb +133 -0
- data/lib/flexmock/expectation_director.rb +6 -4
- data/lib/flexmock/expectation_recorder.rb +42 -0
- data/lib/flexmock/extensions/active_record_model.rb +109 -0
- data/lib/flexmock/mock_builder.rb +139 -0
- data/lib/flexmock/mock_container.rb +13 -214
- data/lib/flexmock/noop.rb +1 -1
- data/lib/flexmock/ordering.rb +1 -2
- data/lib/flexmock/partial_mock.rb +95 -57
- data/lib/flexmock/rails.rb +1 -1
- data/lib/flexmock/recorder.rb +4 -3
- data/lib/flexmock/rspec.rb +1 -1
- data/lib/flexmock/rspec_spy_matcher.rb +4 -0
- data/lib/flexmock/spy_describers.rb +22 -5
- data/lib/flexmock/test_unit.rb +2 -40
- data/lib/flexmock/test_unit_integration.rb +4 -4
- data/lib/flexmock/test_unit_testcase_extensions.rb +49 -0
- data/lib/flexmock/undefined.rb +1 -1
- data/lib/flexmock/validators.rb +18 -12
- data/lib/flexmock/version.rb +1 -1
- data/test/based_partials_test.rb +1 -1
- data/test/container_methods_test.rb +1 -1
- data/test/default_framework_adapter_test.rb +1 -1
- data/test/demeter_mocking_test.rb +52 -2
- data/test/deprecated_methods_test.rb +1 -1
- data/test/examples_from_readme_test.rb +1 -1
- data/test/expectation_description_test.rb +1 -1
- data/test/extended_should_receive_test.rb +1 -1
- data/test/mock_builder_test.rb +68 -0
- data/test/naming_test.rb +1 -1
- data/test/new_instances_test.rb +1 -1
- data/test/partial_mock_test.rb +23 -6
- data/test/record_mode_test.rb +1 -1
- data/test/rspec_integration/integration_spec.rb +1 -1
- data/test/samples_test.rb +1 -2
- data/test/should_ignore_missing_test.rb +1 -1
- data/test/should_receive_test.rb +1 -1
- data/test/test_setup.rb +17 -0
- data/test/test_unit_integration/auto_test_unit_test.rb +1 -1
- data/test/tu_integration_test.rb +1 -1
- data/test/undefined_test.rb +1 -1
- metadata +52 -52
- data/TAGS +0 -1056
- data/lib/flexmock/composite.rb +0 -10
- data/lib/flexmock/rails/view_mocking.rb +0 -144
- data/test/rails_view_stub_test.rb +0 -145
data/lib/flexmock/composite.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'flexmock'
|
2
|
-
|
3
|
-
class FlexMock
|
4
|
-
module MockContainer
|
5
|
-
|
6
|
-
def rails_version
|
7
|
-
Rails::VERSION::STRING
|
8
|
-
end
|
9
|
-
|
10
|
-
# Declare that the Rails controller under test should render the
|
11
|
-
# named view. If a view template name is given, it will be an
|
12
|
-
# error if the named view is not rendered during the execution of
|
13
|
-
# the contoller action. If no template name is given, then the
|
14
|
-
# any view may be rendered. If no view is actually rendered, then
|
15
|
-
# an assertion failure will occur.
|
16
|
-
#
|
17
|
-
# def test_my_action_does_what_it_should
|
18
|
-
# should_render_view 'show'
|
19
|
-
#
|
20
|
-
# get :show, :id => 1
|
21
|
-
#
|
22
|
-
# assert_response :success
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
def should_render_view(template_name=nil)
|
26
|
-
if rails_version <= '1.2.4'
|
27
|
-
should_render_view_prior_version_124(template_name)
|
28
|
-
elsif rails_version <= '2.0.0'
|
29
|
-
should_render_view_after_version_124(template_name)
|
30
|
-
elsif rails_version < '2.2'
|
31
|
-
should_render_view_after_version_202(template_name)
|
32
|
-
elsif rails_version < '2.3'
|
33
|
-
should_render_view_22x(template_name)
|
34
|
-
else
|
35
|
-
should_render_view_23x(template_name)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
# This version of should_render_view will work for Rails 1.2.4
|
42
|
-
# (and prehaps some number of prior versions).
|
43
|
-
def should_render_view_prior_version_124(template_name) # :nodoc:
|
44
|
-
view = flexmock("MockView")
|
45
|
-
view.should_receive(
|
46
|
-
:assigns => {},
|
47
|
-
:render_file => true,
|
48
|
-
:render_partial => true,
|
49
|
-
:first_render => "dummy_template"
|
50
|
-
)
|
51
|
-
if template_name
|
52
|
-
view.should_receive(:file_exists?).with(/#{template_name}$/).once.
|
53
|
-
and_return(true)
|
54
|
-
end
|
55
|
-
view.should_receive(:file_exists?).with(any).and_return(true)
|
56
|
-
view_class = flexmock("MockViewClasss")
|
57
|
-
view_class.should_receive(:new).and_return(view)
|
58
|
-
flexmock(@controller.class).should_receive(:view_class).once.
|
59
|
-
and_return(view_class)
|
60
|
-
end
|
61
|
-
|
62
|
-
# This version of should_render_view will work with versions of
|
63
|
-
# Rails after Version 1.2.4.
|
64
|
-
def should_render_view_after_version_124(template_name)
|
65
|
-
view = flexmock("MockView")
|
66
|
-
view.should_receive(
|
67
|
-
:assigns => {},
|
68
|
-
:render_file => true,
|
69
|
-
:render_partial => true,
|
70
|
-
:template_format => :dummy_format,
|
71
|
-
:view_paths => :dummy_view_paths,
|
72
|
-
:pick_template_extension => :dummy_extension
|
73
|
-
)
|
74
|
-
if template_name
|
75
|
-
view.should_receive(:file_exists?).with(/#{template_name}$/).once.
|
76
|
-
and_return(true)
|
77
|
-
end
|
78
|
-
view.should_receive(:file_exists?).with(any).and_return(true)
|
79
|
-
|
80
|
-
# The number of times this is called changes from version 1.2.6
|
81
|
-
# to 2.0. The important thing is that it is checked at least once.
|
82
|
-
flexmock(@response).should_receive(:template).and_return(view).
|
83
|
-
at_least.once
|
84
|
-
end
|
85
|
-
|
86
|
-
# This version of should_render_view will work with versions of
|
87
|
-
# Rails at Version 2.0.2 and after
|
88
|
-
def should_render_view_after_version_202(template_name)
|
89
|
-
viewmock = flexmock("ViewMock")
|
90
|
-
viewmock.should_receive(
|
91
|
-
:assigns => {},
|
92
|
-
:pick_template_extension => ".html",
|
93
|
-
:template_format =>nil,
|
94
|
-
:view_paths => nil,
|
95
|
-
:file_exists? => true,
|
96
|
-
:first_render => "")
|
97
|
-
if template_name
|
98
|
-
viewmock.should_receive(:render_file).with(/\/#{template_name}$/, any, any).
|
99
|
-
and_return(nil).once
|
100
|
-
viewmock.should_receive(:render_file).and_return(nil)
|
101
|
-
else
|
102
|
-
viewmock.should_receive(:render_file).at_least.once.and_return(nil)
|
103
|
-
end
|
104
|
-
flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
|
105
|
-
end
|
106
|
-
|
107
|
-
# This version of should_render_view will work with versions of
|
108
|
-
# Rails at Version 2.2.x.
|
109
|
-
def should_render_view_22x(template_name)
|
110
|
-
viewmock = flexmock("ViewMock")
|
111
|
-
viewmock.should_receive(
|
112
|
-
:helpers => viewmock,
|
113
|
-
:include => nil,
|
114
|
-
:template_format =>nil,
|
115
|
-
:render => "RENDERED TEXT",
|
116
|
-
:assigns => {})
|
117
|
-
if template_name
|
118
|
-
viewmock.should_receive(:_exempt_from_layout?).with(/\/#{template_name}$/).
|
119
|
-
and_return(true).once
|
120
|
-
viewmock.should_receive(:_exempt_from_layout?).and_return(true)
|
121
|
-
else
|
122
|
-
viewmock.should_receive(:_exempt_from_layout?).at_least.once.and_return(true)
|
123
|
-
end
|
124
|
-
flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
|
125
|
-
end
|
126
|
-
|
127
|
-
# This version of should_render_view will work with versions of
|
128
|
-
# Rails at Version 2.3.x.
|
129
|
-
def should_render_view_23x(template_name)
|
130
|
-
viewmock = flexmock("ViewMock")
|
131
|
-
viewmock.should_receive(
|
132
|
-
:view_paths => viewmock,
|
133
|
-
:render => "RENDERED TEXT")
|
134
|
-
if template_name
|
135
|
-
viewmock.should_receive(:find_template).
|
136
|
-
with(/\/#{template_name}$/, any).
|
137
|
-
and_return(FlexMock.undefined).
|
138
|
-
at_least.once
|
139
|
-
end
|
140
|
-
viewmock.should_ignore_missing
|
141
|
-
flexmock(ActionView::Base).should_receive(:new).and_return(viewmock)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/test_setup'
|
4
|
-
require 'flexmock/rails/view_mocking'
|
5
|
-
|
6
|
-
module ViewTests
|
7
|
-
def test_view_mocks_as_stub
|
8
|
-
should_render_view
|
9
|
-
render "controller/new.rthml"
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_fails_if_no_render
|
13
|
-
should_render_view
|
14
|
-
assert_raise(assertion_failed_error) do
|
15
|
-
flexmock_verify
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_view_mocks_with_expectation
|
20
|
-
should_render_view("new")
|
21
|
-
render "controller/new"
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_view_mocks_with_expectation_fails_with_different_template
|
25
|
-
should_render_view("new")
|
26
|
-
render "controller/edit"
|
27
|
-
assert_raise(assertion_failed_error) do
|
28
|
-
flexmock_verify
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_view_mocks_with_expectation_and_multiple_templates
|
33
|
-
should_render_view("new")
|
34
|
-
render "controller/edit", "controller/show", "controller/new"
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def pretend_to_be_rails_version(version)
|
40
|
-
flexmock(self).should_receive(:rails_version).and_return(version)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
######################################################################
|
45
|
-
class TestRailsViewStubForVersionsUpTo_1_2_4 < Test::Unit::TestCase
|
46
|
-
include FlexMock::TestCase
|
47
|
-
include ViewTests
|
48
|
-
|
49
|
-
def setup
|
50
|
-
@controller_class = flexmock("controller class")
|
51
|
-
@controller = flexmock("controller", :class => @controller_class)
|
52
|
-
pretend_to_be_rails_version("1.2.4")
|
53
|
-
end
|
54
|
-
|
55
|
-
# Simulate Rails rendering in version 1.2.4
|
56
|
-
def render(*names)
|
57
|
-
vc = @controller.class.view_class
|
58
|
-
v = vc.new
|
59
|
-
v.assigns(:x => :y)
|
60
|
-
v.render_file
|
61
|
-
v.first_render
|
62
|
-
names.each do |name|
|
63
|
-
v.file_exists?(name)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
######################################################################
|
70
|
-
class TestRailsViewStubForVersionsAfter_1_2_4 < Test::Unit::TestCase
|
71
|
-
include FlexMock::TestCase
|
72
|
-
include ViewTests
|
73
|
-
|
74
|
-
def setup
|
75
|
-
@controller_class = flexmock("controller class")
|
76
|
-
@controller = flexmock("controller", :class => @controller_class)
|
77
|
-
@response = flexmock("Response")
|
78
|
-
pretend_to_be_rails_version("2.0")
|
79
|
-
end
|
80
|
-
|
81
|
-
# Simulate Rails rendering after Rails version 1.2.4
|
82
|
-
def render(*names)
|
83
|
-
v = @response.template
|
84
|
-
v.assigns(:x => :y)
|
85
|
-
v.render_file
|
86
|
-
v.template_format
|
87
|
-
v.view_paths
|
88
|
-
v.pick_template_extension
|
89
|
-
names.each do |name|
|
90
|
-
v.file_exists?(name)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
######################################################################
|
97
|
-
class TestRailsViewStubForVersionsAfter_2_0_2 < Test::Unit::TestCase
|
98
|
-
include FlexMock::TestCase
|
99
|
-
include ViewTests
|
100
|
-
|
101
|
-
def setup
|
102
|
-
@controller_class = flexmock("controller class")
|
103
|
-
@controller = flexmock("controller", :class => @controller_class)
|
104
|
-
@response = flexmock("Response")
|
105
|
-
pretend_to_be_rails_version("2.0.2")
|
106
|
-
end
|
107
|
-
|
108
|
-
# Simulate Rails rendering after Rails version 2.0.2
|
109
|
-
def render(*names)
|
110
|
-
v = ActionView::Base.new
|
111
|
-
v.assigns(:x => :y)
|
112
|
-
v.template_format
|
113
|
-
v.view_paths
|
114
|
-
v.pick_template_extension
|
115
|
-
names.each do |name|
|
116
|
-
v.file_exists?(name)
|
117
|
-
end
|
118
|
-
v.render_file(names.last, nil, nil)
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
class FlexMock
|
124
|
-
module MockContainer
|
125
|
-
module Rails
|
126
|
-
module VERSION
|
127
|
-
STRING = 1
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
class TestRailsVersion < Test::Unit::TestCase
|
134
|
-
include FlexMock::TestCase
|
135
|
-
def test_rails_version_to_get_code_coverage
|
136
|
-
rails_version
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Test Helper Classes
|
141
|
-
|
142
|
-
module ActionView
|
143
|
-
class Base
|
144
|
-
end
|
145
|
-
end
|