rspec-rails 2.14.0 → 2.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d8abb1f01a347fd1b2a6ec73a1fa43744b8b721
4
- data.tar.gz: 2217552c216c853b6cfb550680193da17b324269
3
+ metadata.gz: 4c053ac2d2a951f4774f401d7b068dece619f61e
4
+ data.tar.gz: a81a760b010b0d6af7e1ad35d6a35228936151e5
5
5
  SHA512:
6
- metadata.gz: 303482e646eba42a2a8b5eb9a3d6634b769337b3a496db7b40098f0fb99f2dbc9ea05c53f7c12e97dc40dec8802ad69a100e8a26269fd3bd938ed0bac011b345
7
- data.tar.gz: 8a4c7c39fe7817b538a3fb79c18cfe9852947c542a7f10b426a491968078f7a4afa6411e8c02f3840c38b7816db6204f10be7734d40fe798d5fe2590c8b71a86
6
+ metadata.gz: 53811242800f841314f83b633db928d3a98e566813dec259dcff79e1387f063a2d6bf93bb826ca74d2c4917464fffbdcf69408e6a929de35c5f424cf1715dcca
7
+ data.tar.gz: 60e09ccad88d509eb2b7e84b60511ada80418ad995a581d1bc4b18414330316b03fb2d709476d088709b2010db5060965d5827f69714821be690f8e1dd46b2c2
@@ -1,3 +1,18 @@
1
+ ### 2.14.1 / 2013-12-29
2
+ [full changelog](http://github.com/rspec/rspec-rails/compare/v2.14.0...v2.14.1)
3
+
4
+ Bug fixes
5
+
6
+ * Fixes "warning: instance variable @orig\_routes not initialized" raised by
7
+ controller specs when `--warnings` are enabled. (Andy Lindeman)
8
+ * Where possible, check against the version of ActiveRecord, rather than
9
+ Rails. It is possible to use some of rspec-rails without all of Rails.
10
+ (Darryl Pogue)
11
+ * Supports Rails 4.1 and Minitest 5. (Patrick Van Stee, Andy Lindeman)
12
+ * Explicitly depends on `activemodel`. This allows libraries that do not bring
13
+ in all of `rails` to use `rspec-rails`. (John Firebaugh)
14
+ * Use `__send__` rather than `send` to prevent naming collisions (Bradley Schaefer)
15
+
1
16
  ### 2.14.0 / 2013-07-06
2
17
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.14.0.rc1...v2.14.0)
3
18
 
@@ -11,7 +11,12 @@ Feature: ActiveRecord::Relation match array
11
11
 
12
12
  describe Widget do
13
13
  let!(:widgets) { Array.new(3) { Widget.create } }
14
- subject { Widget.scoped }
14
+
15
+ if ::Rails::VERSION::STRING >= '4'
16
+ subject { Widget.all }
17
+ else
18
+ subject { Widget.scoped }
19
+ end
15
20
 
16
21
  it "returns all widgets in any order" do
17
22
  expect(subject).to match_array(widgets)
@@ -10,7 +10,7 @@ Feature: errors_on
10
10
  validates_presence_of :name
11
11
 
12
12
  # In Rails 4, mass assignment protection is implemented on controllers
13
- attr_accessible :name if ::Rails::VERSION::STRING < '4'
13
+ attr_accessible :name if ::ActiveRecord::VERSION::STRING < '4'
14
14
 
15
15
  validates_length_of :name, :minimum => 10, :on => :publication
16
16
  end
@@ -0,0 +1,6 @@
1
+ # Required until https://github.com/rubinius/rubinius/issues/2430 is resolved
2
+ ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc"
3
+
4
+ Around "@unsupported-on-rbx" do |scenario, block|
5
+ block.call unless defined?(Rubinius)
6
+ end
@@ -1,14 +1,29 @@
1
1
  require 'delegate'
2
2
  require 'active_support/concern'
3
- require 'test/unit/assertions'
4
3
 
5
4
  module RSpec
6
5
  module Rails
6
+ if ::Rails::VERSION::STRING >= '4.1.0'
7
+ gem 'minitest'
8
+ require 'minitest/assertions'
9
+ Assertions = Minitest::Assertions
10
+ else
11
+ begin
12
+ require 'test/unit/assertions'
13
+ rescue LoadError
14
+ # work around for Rubinius not having a std std-lib
15
+ require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
16
+ require 'test/unit/assertions'
17
+ end
18
+ Assertions = Test::Unit::Assertions
19
+ end
20
+
21
+ # @api private
7
22
  class AssertionDelegator < Module
8
23
  # @api private
9
24
  def initialize(*assertion_modules)
10
25
  assertion_class = Class.new(SimpleDelegator) do
11
- include Test::Unit::Assertions
26
+ include ::RSpec::Rails::Assertions
12
27
  include ::RSpec::Rails::MinitestCounters
13
28
  assertion_modules.each { |mod| include mod }
14
29
  end
@@ -38,8 +53,10 @@ module RSpec
38
53
  end
39
54
  end
40
55
 
41
- # MiniTest::Unit::LifecycleHooks
42
- module MiniTestLifecycleAdapter
56
+ # Adapts example groups for `Minitest::Test::LifecycleHooks`
57
+ #
58
+ # @api private
59
+ module MinitestLifecycleAdapter
43
60
  extend ActiveSupport::Concern
44
61
 
45
62
  included do |group|
@@ -79,6 +96,7 @@ module RSpec
79
96
  end
80
97
  end
81
98
 
99
+ # @api private
82
100
  module SetupAndTeardownAdapter
83
101
  extend ActiveSupport::Concern
84
102
 
@@ -89,10 +107,10 @@ module RSpec
89
107
  # hooks.
90
108
  def setup(*methods)
91
109
  methods.each do |method|
92
- if method.to_s =~ /^setup_(fixtures|controller_request_and_response)$/
93
- prepend_before { send method }
110
+ if method.to_s =~ /^setup_(with_controller|fixtures|controller_request_and_response)$/
111
+ prepend_before { __send__ method }
94
112
  else
95
- before { send method }
113
+ before { __send__ method }
96
114
  end
97
115
  end
98
116
  end
@@ -102,7 +120,7 @@ module RSpec
102
120
  # Wraps `teardown` calls from within Rails' testing framework in
103
121
  # `after` hooks.
104
122
  def teardown(*methods)
105
- methods.each { |method| after { send method } }
123
+ methods.each { |method| after { __send__ method } }
106
124
  end
107
125
  end
108
126
 
@@ -112,7 +130,8 @@ module RSpec
112
130
  end
113
131
  end
114
132
 
115
- module TestUnitAssertionAdapter
133
+ # @private
134
+ module MinitestAssertionAdapter
116
135
  extend ActiveSupport::Concern
117
136
 
118
137
  module ClassMethods
@@ -122,7 +141,7 @@ module RSpec
122
141
  # examples without exposing non-assertion methods in Test::Unit or
123
142
  # Minitest.
124
143
  def assertion_method_names
125
- Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/} +
144
+ ::RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/} +
126
145
  [:build_message]
127
146
  end
128
147
 
@@ -138,8 +157,9 @@ module RSpec
138
157
  end
139
158
  end
140
159
 
160
+ # @api private
141
161
  class AssertionDelegator
142
- include Test::Unit::Assertions
162
+ include ::RSpec::Rails::Assertions
143
163
  include ::RSpec::Rails::MinitestCounters
144
164
  end
145
165
 
@@ -152,5 +172,11 @@ module RSpec
152
172
  define_assertion_delegators
153
173
  end
154
174
  end
175
+
176
+ # Backwards compatibility. It's unlikely that anyone is using this
177
+ # constant, but we had forgotten to mark it as `@private` earlier
178
+ #
179
+ # @api private
180
+ TestUnitAssertionAdapter = MinitestAssertionAdapter
155
181
  end
156
182
  end
@@ -135,7 +135,7 @@ module RSpec::Rails
135
135
  def method_missing(method, *args, &block)
136
136
  if @routes && @routes.named_routes.helpers.include?(method)
137
137
  controller.send(method, *args, &block)
138
- elsif @orig_routes && @orig_routes.named_routes.helpers.include?(method)
138
+ elsif defined?(@orig_routes) && @orig_routes && @orig_routes.named_routes.helpers.include?(method)
139
139
  controller.send(method, *args, &block)
140
140
  else
141
141
  super
@@ -7,8 +7,8 @@ module RSpec
7
7
  module RailsExampleGroup
8
8
  extend ActiveSupport::Concern
9
9
  include RSpec::Rails::SetupAndTeardownAdapter
10
- include RSpec::Rails::MiniTestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
11
- include RSpec::Rails::TestUnitAssertionAdapter
10
+ include RSpec::Rails::MinitestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
11
+ include RSpec::Rails::MinitestAssertionAdapter
12
12
  include RSpec::Rails::Matchers
13
13
  end
14
14
  end
@@ -156,6 +156,9 @@ module RSpec::Rails
156
156
  view.lookup_context.prefixes << _controller_path
157
157
  end
158
158
 
159
+ # fixes bug with differing formats
160
+ view.lookup_context.view_paths.each(&:clear_cache)
161
+
159
162
  controller.controller_path = _controller_path
160
163
  controller.request.path_parameters[:controller] = _controller_path
161
164
  controller.request.path_parameters[:action] = _inferred_action unless _inferred_action =~ /^_/
@@ -3,14 +3,14 @@ module RSpec
3
3
  if defined?(ActiveRecord)
4
4
  module Extensions
5
5
  module ActiveRecord
6
- # Extension to enhance `should have` on AR Model classes
6
+ # Extension to enhance `to have` on AR Model classes
7
7
  #
8
8
  # @example
9
9
  #
10
10
  # ModelClass.should have(:no).records
11
11
  # ModelClass.should have(1).record
12
12
  # ModelClass.should have(n).records
13
- if ::Rails::VERSION::STRING >= '4'
13
+ if ::ActiveRecord::VERSION::STRING >= '4'
14
14
  def records
15
15
  all.to_a
16
16
  end
@@ -32,7 +32,7 @@ end
32
32
 
33
33
  if defined?(::ActiveModel)
34
34
  module ::ActiveModel::Validations
35
- # Extension to enhance `should have` on AR Model instances. Calls
35
+ # Extension to enhance `to have` on AR Model instances. Calls
36
36
  # model.valid? in order to prepare the object's errors object. Accepts
37
37
  # a :context option to specify the validation context.
38
38
  #
@@ -40,12 +40,12 @@ if defined?(::ActiveModel)
40
40
  #
41
41
  # @example
42
42
  #
43
- # model.should have(:no).errors_on(:attribute)
44
- # model.should have(1).error_on(:attribute)
45
- # model.should have(n).errors_on(:attribute)
46
- # model.should have(n).errors_on(:attribute, :context => :create)
43
+ # expect(model).to have(:no).errors_on(:attribute)
44
+ # expect(model).to have(1).error_on(:attribute)
45
+ # expect(model).to have(n).errors_on(:attribute)
46
+ # expect(model).to have(n).errors_on(:attribute, :context => :create)
47
47
  #
48
- # model.errors_on(:attribute).should include("can't be blank")
48
+ # expect(model.errors_on(:attribute)).to include("can't be blank")
49
49
  def errors_on(attribute, options = {})
50
50
  valid_args = [options[:context]].compact
51
51
  self.valid?(*valid_args)
@@ -4,8 +4,8 @@ module RSpec
4
4
  module FixtureSupport
5
5
  extend ActiveSupport::Concern
6
6
  include RSpec::Rails::SetupAndTeardownAdapter
7
- include RSpec::Rails::MiniTestLifecycleAdapter if ::Rails::VERSION::STRING > '4'
8
- include RSpec::Rails::TestUnitAssertionAdapter
7
+ include RSpec::Rails::MinitestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4'
8
+ include RSpec::Rails::MinitestAssertionAdapter
9
9
  include ActiveRecord::TestFixtures
10
10
 
11
11
  included do
@@ -29,6 +29,19 @@ module RSpec
29
29
  end
30
30
  end
31
31
 
32
+ # Starting with Rails 4.1, ActiveRecord associations are inversible
33
+ # by default. This class represents an association from the mocked
34
+ # model's perspective.
35
+ #
36
+ # @private
37
+ class Association
38
+ attr_accessor :target, :inversed
39
+
40
+ def initialize(association_name)
41
+ @association_name = association_name
42
+ end
43
+ end
44
+
32
45
  module ActiveRecordInstanceMethods
33
46
  # Stubs `persisted?` to return `false` and `id` to return `nil`.
34
47
  def destroy
@@ -45,6 +58,13 @@ module RSpec
45
58
  def new_record?
46
59
  !persisted?
47
60
  end
61
+
62
+ # Returns an object representing an association from the mocked
63
+ # model's perspective. For use by Rails internally only.
64
+ def association(association_name)
65
+ @associations ||= Hash.new { |h, k| h[k] = Association.new(k) }
66
+ @associations[association_name]
67
+ end
48
68
  end
49
69
 
50
70
  # Creates a test double representing `string_or_model_class` with common
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module Version
4
- STRING = '2.14.0'
4
+ STRING = '2.14.1'
5
5
  end
6
6
  end
7
7
  end
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
- describe RSpec::Rails::TestUnitAssertionAdapter do
4
- include RSpec::Rails::TestUnitAssertionAdapter
3
+ describe RSpec::Rails::MinitestAssertionAdapter do
4
+ include RSpec::Rails::MinitestAssertionAdapter
5
5
 
6
- Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/}.each do |m|
6
+ RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/}.each do |m|
7
7
  if m.to_s == "assert_equal"
8
8
  it "exposes #{m} to host examples" do
9
9
  assert_equal 3,3
@@ -18,11 +18,11 @@ describe RSpec::Rails::TestUnitAssertionAdapter do
18
18
  end
19
19
  end
20
20
 
21
- it "does not expose internal methods of MiniTest" do
21
+ it "does not expose internal methods of Minitest" do
22
22
  methods.should_not include("_assertions")
23
23
  end
24
24
 
25
- it "does not expose MiniTest's message method" do
25
+ it "does not expose Minitest's message method" do
26
26
  methods.should_not include("message")
27
27
  end
28
28
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe RSpec::Rails::AssertionDelegator do
4
4
  it "provides a module that delegates assertion methods to an isolated class" do
5
5
  klass = Class.new {
6
- include RSpec::Rails::AssertionDelegator.new(Test::Unit::Assertions)
6
+ include RSpec::Rails::AssertionDelegator.new(RSpec::Rails::Assertions)
7
7
  }
8
8
 
9
9
  expect(klass.new).to respond_to(:assert)
@@ -194,6 +194,21 @@ module RSpec::Rails
194
194
  view_spec.stub(:_view) { view }
195
195
  view_spec.view.should == view
196
196
  end
197
+
198
+ it 'is accessible to hooks' do
199
+ with_isolated_config do
200
+ run_count = 0
201
+ RSpec.configuration.before(:each, :type => :view) do
202
+ allow(view).to receive(:a_stubbed_helper) { :value }
203
+ run_count += 1
204
+ end
205
+ group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
206
+ specify { true }
207
+ end
208
+ group.run NullObject.new
209
+ expect(run_count).to eq 1
210
+ end
211
+ end
197
212
  end
198
213
 
199
214
  describe "#template" do
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
- describe RSpec::Rails::MiniTestLifecycleAdapter do
3
+ describe RSpec::Rails::MinitestLifecycleAdapter do
4
4
  it "invokes minitest lifecycle hooks at the appropriate times" do
5
5
  invocations = []
6
- example_group = RSpec::Core::ExampleGroup.describe("MiniTestHooks") do
7
- include RSpec::Rails::MiniTestLifecycleAdapter
6
+ example_group = RSpec::Core::ExampleGroup.describe("MinitestHooks") do
7
+ include RSpec::Rails::MinitestLifecycleAdapter
8
8
 
9
9
  define_method(:before_setup) { invocations << :before_setup }
10
10
  define_method(:after_setup) { invocations << :after_setup }
@@ -19,4 +19,13 @@ describe RSpec::Rails::MiniTestLifecycleAdapter do
19
19
  :before_setup, :after_setup, :example, :before_teardown, :after_teardown
20
20
  ])
21
21
  end
22
+
23
+ it "allows let variables named 'send'" do
24
+ run_result = ::RSpec::Core::ExampleGroup.describe do
25
+ let(:send) { "WHAT" }
26
+ specify { expect(send).to eq "WHAT" }
27
+ end.run NullObject.new
28
+
29
+ expect(run_result).to be true
30
+ end
22
31
  end
@@ -54,6 +54,29 @@ describe "mock_model(RealModel)" do
54
54
  end
55
55
  end
56
56
 
57
+ describe "association" do
58
+ it "constructs a mock association object" do
59
+ model = mock_model(MockableModel)
60
+ expect(model.association(:association_name)).to be
61
+ end
62
+
63
+ it "returns a different association object for each association name" do
64
+ model = mock_model(MockableModel)
65
+ posts = model.association(:posts)
66
+ authors = model.association(:authors)
67
+
68
+ expect(posts).not_to equal(authors)
69
+ end
70
+
71
+ it "returns the same association model each time for the same association name" do
72
+ model = mock_model(MockableModel)
73
+ posts1 = model.association(:posts)
74
+ posts2 = model.association(:posts)
75
+
76
+ expect(posts1).to equal(posts2)
77
+ end
78
+ end
79
+
57
80
  describe "errors" do
58
81
  context "default" do
59
82
  it "is empty" do
@@ -360,9 +383,8 @@ describe "mock_model(RealModel)" do
360
383
  end
361
384
 
362
385
  describe "ActiveModel Lint tests" do
363
- require 'test/unit/assertions'
364
386
  require 'active_model/lint'
365
- include RSpec::Rails::TestUnitAssertionAdapter
387
+ include RSpec::Rails::MinitestAssertionAdapter
366
388
  include ActiveModel::Lint::Tests
367
389
 
368
390
  # to_s is to support ruby-1.9
@@ -2,6 +2,7 @@ require 'rails/all'
2
2
 
3
3
  module RSpecRails
4
4
  class Application < ::Rails::Application
5
+ self.config.secret_key_base = 'ASecretString' if config.respond_to? :secret_key_base
5
6
  end
6
7
  end
7
8
 
@@ -16,5 +16,19 @@ module Helpers
16
16
  m
17
17
  end
18
18
 
19
+ def with_isolated_config
20
+ original_config = RSpec.configuration
21
+ RSpec.configuration = RSpec::Core::Configuration.new
22
+ RSpec.configure do |c|
23
+ c.include RSpec::Rails::FixtureSupport
24
+ c.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
25
+ c.add_setting :use_instantiated_fixtures
26
+ c.add_setting :global_fixtures
27
+ c.add_setting :fixture_path
28
+ end
29
+ yield
30
+ RSpec.configuration = original_config
31
+ end
32
+
19
33
  RSpec.configure {|c| c.include self}
20
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: actionpack
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +128,14 @@ dependencies:
114
128
  requirements:
115
129
  - - ~>
116
130
  - !ruby/object:Gem::Version
117
- version: 1.1.9
131
+ version: 1.3.5
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - ~>
123
137
  - !ruby/object:Gem::Version
124
- version: 1.1.9
138
+ version: 1.3.5
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: aruba
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +154,16 @@ dependencies:
140
154
  name: ZenTest
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - '='
157
+ - - ~>
144
158
  - !ruby/object:Gem::Version
145
- version: 4.9.0
159
+ version: 4.9.5
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - '='
164
+ - - ~>
151
165
  - !ruby/object:Gem::Version
152
- version: 4.9.0
166
+ version: 4.9.5
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: ammeter
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +306,7 @@ files:
292
306
  - features/step_definitions/model_steps.rb
293
307
  - features/support/env.rb
294
308
  - features/support/rails_versions.rb
309
+ - features/support/rubinius.rb
295
310
  - features/view_specs/inferred_controller_path.feature
296
311
  - features/view_specs/stub_template.feature
297
312
  - features/view_specs/view_spec.feature
@@ -361,10 +376,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
361
376
  version: '0'
362
377
  requirements: []
363
378
  rubyforge_project: rspec
364
- rubygems_version: 2.0.3
379
+ rubygems_version: 2.0.14
365
380
  signing_key:
366
381
  specification_version: 4
367
- summary: rspec-rails-2.14.0
382
+ summary: rspec-rails-2.14.1
368
383
  test_files:
369
384
  - features/Autotest.md
370
385
  - features/Generators.md
@@ -405,6 +420,7 @@ test_files:
405
420
  - features/step_definitions/model_steps.rb
406
421
  - features/support/env.rb
407
422
  - features/support/rails_versions.rb
423
+ - features/support/rubinius.rb
408
424
  - features/view_specs/inferred_controller_path.feature
409
425
  - features/view_specs/stub_template.feature
410
426
  - features/view_specs/view_spec.feature