rspec-rails 2.8.0.rc1 → 2.8.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/License.txt +22 -0
  2. data/README.md +253 -119
  3. data/features/README.md +0 -2
  4. data/features/Upgrade.md +1 -1
  5. data/lib/generators/rspec/install/templates/spec/spec_helper.rb +1 -1
  6. data/lib/generators/rspec/integration/integration_generator.rb +1 -0
  7. data/lib/generators/rspec/scaffold/scaffold_generator.rb +1 -0
  8. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +23 -16
  9. data/lib/rspec/rails/adapters.rb +25 -13
  10. data/lib/rspec/rails/example/controller_example_group.rb +65 -122
  11. data/lib/rspec/rails/example/helper_example_group.rb +11 -36
  12. data/lib/rspec/rails/example/mailer_example_group.rb +1 -1
  13. data/lib/rspec/rails/example/rails_example_group.rb +5 -0
  14. data/lib/rspec/rails/example/request_example_group.rb +4 -19
  15. data/lib/rspec/rails/example/routing_example_group.rb +8 -10
  16. data/lib/rspec/rails/example/view_example_group.rb +21 -35
  17. data/lib/rspec/rails/extensions/active_record/base.rb +15 -12
  18. data/lib/rspec/rails/fixture_support.rb +1 -1
  19. data/lib/rspec/rails/matchers/be_a_new.rb +63 -30
  20. data/lib/rspec/rails/matchers/be_new_record.rb +18 -3
  21. data/lib/rspec/rails/matchers/have_extension.rb +26 -14
  22. data/lib/rspec/rails/matchers/redirect_to.rb +26 -7
  23. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  24. data/lib/rspec/rails/matchers/render_template.rb +27 -8
  25. data/lib/rspec/rails/matchers/routing_matchers.rb +72 -24
  26. data/lib/rspec/rails/mocks.rb +42 -34
  27. data/lib/rspec/rails/module_inclusion.rb +2 -1
  28. data/lib/rspec/rails/version.rb +1 -1
  29. data/lib/rspec/rails/view_assigns.rb +31 -34
  30. data/lib/rspec/rails/view_rendering.rb +10 -6
  31. data/spec/rspec/rails/example/controller_example_group_spec.rb +2 -2
  32. data/spec/rspec/rails/example/helper_example_group_spec.rb +5 -5
  33. data/spec/rspec/rails/example/view_example_group_spec.rb +5 -5
  34. data/spec/rspec/rails/matchers/be_a_new_spec.rb +2 -0
  35. data/spec/rspec/rails/matchers/be_new_record_spec.rb +2 -0
  36. data/spec/rspec/rails/matchers/render_template_spec.rb +3 -5
  37. data/spec/rspec/rails/mocks/mock_model_spec.rb +28 -0
  38. metadata +22 -19
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module Version
4
- STRING = '2.8.0.rc1'
4
+ STRING = '2.8.0.rc2'
5
5
  end
6
6
  end
7
7
  end
@@ -1,46 +1,43 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module ViewAssigns
4
- extend ActiveSupport::Concern
5
-
6
- module InstanceMethods
7
- # Assigns a value to an instance variable in the scope of the
8
- # view being rendered.
9
- #
10
- # == Examples
11
- #
12
- # assign(:widget, stub_model(Widget))
13
- def assign(key, value)
14
- _encapsulated_assigns[key] = value
15
- end
16
-
17
- def view_assigns
18
- begin
19
- # TODO: _assigns was deprecated in favor of view_assigns after
20
- # Rails-3.0.0 was released. Since we are not able to predict when
21
- # the _assigns/view_assigns patch will be released (I thought it
22
- # would have been in 3.0.1, but 3.0.1 bypassed this change for a
23
- # security fix), this bit ensures that we do the right thing without
24
- # knowing anything about the Rails version we are dealing with.
25
- #
26
- # Once that change _is_ released, this can be changed to something
27
- # that checks for the Rails version when the module is being
28
- # interpreted, as it was before commit dd0095.
29
- super.merge(_encapsulated_assigns)
30
- rescue
31
- _assigns
32
- end
33
- end
4
+ # Assigns a value to an instance variable in the scope of the
5
+ # view being rendered.
6
+ #
7
+ # @example
8
+ #
9
+ # assign(:widget, stub_model(Widget))
10
+ def assign(key, value)
11
+ _encapsulated_assigns[key] = value
12
+ end
34
13
 
35
- def _assigns
14
+ def view_assigns
15
+ begin
16
+ # TODO: _assigns was deprecated in favor of view_assigns after
17
+ # Rails-3.0.0 was released. Since we are not able to predict when
18
+ # the _assigns/view_assigns patch will be released (I thought it
19
+ # would have been in 3.0.1, but 3.0.1 bypassed this change for a
20
+ # security fix), this bit ensures that we do the right thing without
21
+ # knowing anything about the Rails version we are dealing with.
22
+ #
23
+ # Once that change _is_ released, this can be changed to something
24
+ # that checks for the Rails version when the module is being
25
+ # interpreted, as it was before commit dd0095.
36
26
  super.merge(_encapsulated_assigns)
27
+ rescue
28
+ _assigns
37
29
  end
30
+ end
31
+
32
+ # @api private
33
+ def _assigns
34
+ super.merge(_encapsulated_assigns)
35
+ end
38
36
 
39
37
  private
40
38
 
41
- def _encapsulated_assigns
42
- @_encapsulated_assigns ||= {}
43
- end
39
+ def _encapsulated_assigns
40
+ @_encapsulated_assigns ||= {}
44
41
  end
45
42
 
46
43
  end
@@ -34,25 +34,26 @@ module RSpec
34
34
  metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
35
35
  end
36
36
 
37
- # See RSpec::Rails::ControllerExampleGroup
37
+ # @see RSpec::Rails::ControllerExampleGroup
38
38
  def render_views(true_or_false=true)
39
39
  metadata_for_rspec_rails[:render_views] = true_or_false
40
40
  end
41
41
 
42
+ # @deprecated Use `render_views` instead.
42
43
  def integrate_views
43
44
  RSpec.deprecate("integrate_views","render_views")
44
45
  render_views
45
46
  end
46
47
 
48
+ # @api private
47
49
  def render_views?
48
50
  metadata_for_rspec_rails[:render_views] || RSpec.configuration.render_views?
49
51
  end
50
52
  end
51
53
 
52
- module InstanceMethods
53
- def render_views?
54
- self.class.render_views? || !controller.class.respond_to?(:view_paths)
55
- end
54
+ # @api private
55
+ def render_views?
56
+ self.class.render_views? || !controller.class.respond_to?(:view_paths)
56
57
  end
57
58
 
58
59
  # Delegates find_all to the submitted path set and then returns templates
@@ -64,6 +65,7 @@ module RSpec
64
65
  @original_path_set = original_path_set
65
66
  end
66
67
 
68
+ # @api private
67
69
  def find_all(*args)
68
70
  original_path_set.find_all(*args).collect do |template|
69
71
  ::ActionView::Template.new(
@@ -80,15 +82,18 @@ module RSpec
80
82
  end
81
83
 
82
84
  module EmptyTemplates
85
+ # @api private
83
86
  def prepend_view_path(new_path)
84
87
  lookup_context.view_paths.unshift(*_path_decorator(new_path))
85
88
  end
86
89
 
90
+ # @api private
87
91
  def append_view_path(new_path)
88
92
  lookup_context.view_paths.push(*_path_decorator(new_path))
89
93
  end
90
94
 
91
95
  private
96
+
92
97
  def _path_decorator(path)
93
98
  EmptyTemplatePathSetDecorator.new(::ActionView::Base::process_view_paths(path))
94
99
  end
@@ -109,7 +114,6 @@ module RSpec
109
114
  end
110
115
  end
111
116
  end
112
-
113
117
  end
114
118
  end
115
119
  end
@@ -84,7 +84,7 @@ module RSpec::Rails
84
84
  RSpec.configuration.stub(:infer_base_class_for_anonymous_controllers?).and_return(true)
85
85
  group.controller { }
86
86
 
87
- controller_class = group.metadata[:example_group][:describes]
87
+ controller_class = group.metadata[:example_group][:described_class]
88
88
  controller_class.superclass.should eq(group.controller_class)
89
89
  end
90
90
 
@@ -92,7 +92,7 @@ module RSpec::Rails
92
92
  RSpec.configuration.stub(:infer_base_class_for_anonymous_controllers?).and_return(false)
93
93
  group.controller { }
94
94
 
95
- controller_class = group.metadata[:example_group][:describes]
95
+ controller_class = group.metadata[:example_group][:described_class]
96
96
  controller_class.superclass.should eq(ApplicationController)
97
97
  end
98
98
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module RSpec::Rails
4
- describe HelperExampleGroup::InstanceMethods do
4
+ describe HelperExampleGroup do
5
5
  module ::FoosHelper; end
6
6
  subject { HelperExampleGroup }
7
7
 
@@ -9,8 +9,8 @@ module RSpec::Rails
9
9
  it { should be_included_in_files_in('.\\spec\\helpers\\') }
10
10
 
11
11
  it "provides a controller_path based on the helper module's name" do
12
- helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
13
- helper_spec.stub_chain(:example, :example_group, :describes).and_return(FoosHelper)
12
+ helper_spec = Object.new.extend HelperExampleGroup
13
+ helper_spec.stub_chain(:example, :example_group, :described_class).and_return(FoosHelper)
14
14
  helper_spec.__send__(:_controller_path).should == "foos"
15
15
  end
16
16
 
@@ -23,7 +23,7 @@ module RSpec::Rails
23
23
 
24
24
  describe "#helper" do
25
25
  it "returns the instance of AV::Base provided by AV::TC::Behavior" do
26
- helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
26
+ helper_spec = Object.new.extend HelperExampleGroup
27
27
  helper_spec.should_receive(:view_assigns)
28
28
  av_tc_b_view = double('_view')
29
29
  av_tc_b_view.should_receive(:assign)
@@ -55,7 +55,7 @@ module RSpec::Rails
55
55
  describe "determine_default_helper_class" do
56
56
  it "returns the helper module passed to describe" do
57
57
  helper_spec = Object.new.extend HelperExampleGroup::ClassMethods
58
- helper_spec.stub(:describes) { FoosHelper }
58
+ helper_spec.stub(:described_class) { FoosHelper }
59
59
  helper_spec.determine_default_helper_class("ignore this").
60
60
  should eq(FoosHelper)
61
61
  end
@@ -94,7 +94,7 @@ module RSpec::Rails
94
94
  end
95
95
  end
96
96
  include Local
97
- include ViewExampleGroup::InstanceMethods
97
+ include ViewExampleGroup::ExampleMethods
98
98
  end.new
99
99
  end
100
100
 
@@ -124,7 +124,7 @@ module RSpec::Rails
124
124
  describe '#params' do
125
125
  let(:view_spec) do
126
126
  Class.new do
127
- include ViewExampleGroup::InstanceMethods
127
+ include ViewExampleGroup::ExampleMethods
128
128
  def controller
129
129
  @controller ||= Object.new
130
130
  end
@@ -140,7 +140,7 @@ module RSpec::Rails
140
140
  describe "#_controller_path" do
141
141
  let(:view_spec) do
142
142
  Class.new do
143
- include ViewExampleGroup::InstanceMethods
143
+ include ViewExampleGroup::ExampleMethods
144
144
  end.new
145
145
  end
146
146
  context "with a common _default_file_to_render" do
@@ -165,7 +165,7 @@ module RSpec::Rails
165
165
  describe "#view" do
166
166
  let(:view_spec) do
167
167
  Class.new do
168
- include ViewExampleGroup::InstanceMethods
168
+ include ViewExampleGroup::ExampleMethods
169
169
  end.new
170
170
  end
171
171
 
@@ -179,7 +179,7 @@ module RSpec::Rails
179
179
  describe "#template" do
180
180
  let(:view_spec) do
181
181
  Class.new do
182
- include ViewExampleGroup::InstanceMethods
182
+ include ViewExampleGroup::ExampleMethods
183
183
  def _view; end
184
184
  end.new
185
185
  end
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "be_a_new matcher" do
4
+ include RSpec::Rails::Matchers
5
+
4
6
  context "new record" do
5
7
  let(:record) do
6
8
  Class.new do
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "be_new_record" do
4
+ include RSpec::Rails::Matchers
5
+
4
6
  context "un-persisted record" do
5
7
  it "passes" do
6
8
  record = double('record', :persisted? => false)
@@ -61,7 +61,7 @@ describe "render_template" do
61
61
  context "with should_not" do
62
62
  context "when assert_template fails" do
63
63
  it "passes" do
64
- self.stub!(:assert_template) do
64
+ def assert_template(*)
65
65
  raise ActiveSupport::TestCase::Assertion.new("this message")
66
66
  end
67
67
  expect do
@@ -72,7 +72,7 @@ describe "render_template" do
72
72
 
73
73
  context "when assert_template passes" do
74
74
  it "fails with custom failure message" do
75
- self.stub!(:assert_template)
75
+ def assert_template(*); end
76
76
  expect do
77
77
  response.should_not render_template("template_name")
78
78
  end.to raise_error(/expected not to render \"template_name\", but did/)
@@ -81,9 +81,7 @@ describe "render_template" do
81
81
 
82
82
  context "when fails due to some other exception" do
83
83
  it "raises that exception" do
84
- self.stub!(:assert_template) do
85
- raise "oops"
86
- end
84
+ def assert_template(*); raise "oops"; end
87
85
  expect do
88
86
  response.should_not render_template("template_name")
89
87
  end.to raise_exception("oops")
@@ -188,6 +188,34 @@ describe "mock_model(RealModel)" do
188
188
  it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
189
189
  @model.respond_to?("column_a").should be(true)
190
190
  end
191
+ it "stubs column accessor (with string)" do
192
+ @model.respond_to?("column_a")
193
+ @model.column_a.should be_nil
194
+ end
195
+ it "stubs column accessor (with symbol)" do
196
+ @model.respond_to?(:column_a)
197
+ @model.column_a.should be_nil
198
+ end
199
+ it "does not stub column accessor if already stubbed in declaration (with string)" do
200
+ model = mock_model(MockableModel, "column_a" => "a")
201
+ model.respond_to?("column_a")
202
+ model.column_a.should eq("a")
203
+ end
204
+ it "does not stub column accessor if already stubbed in declaration (with symbol)" do
205
+ model = mock_model(MockableModel, :column_a => "a")
206
+ model.respond_to?("column_a")
207
+ model.column_a.should eq("a")
208
+ end
209
+ it "does not stub column accessor if already stubbed after declaration (with string)" do
210
+ @model.stub("column_a" => "a")
211
+ @model.respond_to?("column_a")
212
+ @model.column_a.should eq("a")
213
+ end
214
+ it "does not stub column accessor if already stubbed after declaration (with symbol)" do
215
+ @model.stub(:column_a => "a")
216
+ @model.respond_to?("column_a")
217
+ @model.column_a.should eq("a")
218
+ end
191
219
  it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
192
220
  @model.respond_to?("column_c").should be(false)
193
221
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424215
4
+ hash: 15424209
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
9
  - 0
10
10
  - rc
11
- - 1
12
- version: 2.8.0.rc1
11
+ - 2
12
+ version: 2.8.0.rc2
13
13
  platform: ruby
14
14
  authors:
15
15
  - David Chelimsky
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-11-06 00:00:00 Z
20
+ date: 2011-12-20 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -30,10 +30,10 @@ dependencies:
30
30
  - 3
31
31
  - 0
32
32
  version: "3.0"
33
- requirement: *id001
34
- type: :runtime
35
33
  prerelease: false
34
+ requirement: *id001
36
35
  name: activesupport
36
+ type: :runtime
37
37
  - !ruby/object:Gem::Dependency
38
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -45,10 +45,10 @@ dependencies:
45
45
  - 3
46
46
  - 0
47
47
  version: "3.0"
48
- requirement: *id002
49
- type: :runtime
50
48
  prerelease: false
49
+ requirement: *id002
51
50
  name: actionpack
51
+ type: :runtime
52
52
  - !ruby/object:Gem::Dependency
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -60,36 +60,37 @@ dependencies:
60
60
  - 3
61
61
  - 0
62
62
  version: "3.0"
63
- requirement: *id003
64
- type: :runtime
65
63
  prerelease: false
64
+ requirement: *id003
66
65
  name: railties
66
+ type: :runtime
67
67
  - !ruby/object:Gem::Dependency
68
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
71
71
  - - "="
72
72
  - !ruby/object:Gem::Version
73
- hash: 15424215
73
+ hash: 15424209
74
74
  segments:
75
75
  - 2
76
76
  - 8
77
77
  - 0
78
78
  - rc
79
- - 1
80
- version: 2.8.0.rc1
81
- requirement: *id004
82
- type: :runtime
79
+ - 2
80
+ version: 2.8.0.rc2
83
81
  prerelease: false
82
+ requirement: *id004
84
83
  name: rspec
84
+ type: :runtime
85
85
  description: RSpec-2 for Rails-3
86
- email: dchelimsky@gmail.com
86
+ email: rspec-users@rubyforge.org
87
87
  executables: []
88
88
 
89
89
  extensions: []
90
90
 
91
91
  extra_rdoc_files:
92
92
  - README.md
93
+ - License.txt
93
94
  files:
94
95
  - lib/autotest/rails_rspec2.rb
95
96
  - lib/generators/rspec.rb
@@ -151,6 +152,7 @@ files:
151
152
  - lib/rspec/rails/version.rb
152
153
  - lib/rspec/rails/view_assigns.rb
153
154
  - lib/rspec/rails/view_rendering.rb
155
+ - License.txt
154
156
  - README.md
155
157
  - features/Autotest.md
156
158
  - features/Generators.md
@@ -228,8 +230,8 @@ files:
228
230
  - spec/support/helpers.rb
229
231
  - spec/support/matchers.rb
230
232
  homepage: http://github.com/rspec/rspec-rails
231
- licenses: []
232
-
233
+ licenses:
234
+ - MIT
233
235
  post_install_message:
234
236
  rdoc_options:
235
237
  - --charset=UTF-8
@@ -261,7 +263,7 @@ rubyforge_project: rspec
261
263
  rubygems_version: 1.8.11
262
264
  signing_key:
263
265
  specification_version: 3
264
- summary: rspec-rails-2.8.0.rc1
266
+ summary: rspec-rails-2.8.0.rc2
265
267
  test_files:
266
268
  - features/Autotest.md
267
269
  - features/Generators.md
@@ -338,3 +340,4 @@ test_files:
338
340
  - spec/support/ar_classes.rb
339
341
  - spec/support/helpers.rb
340
342
  - spec/support/matchers.rb
343
+ has_rdoc: