rspec-rails 2.99.0 → 3.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +40 -68
  5. data/License.txt +1 -0
  6. data/README.md +6 -4
  7. data/features/Generators.md +24 -0
  8. data/features/GettingStarted.md +84 -0
  9. data/features/README.md +56 -0
  10. data/features/RailsVersions.md +4 -0
  11. data/features/Transactions.md +84 -0
  12. data/features/Upgrade.md +121 -0
  13. data/features/controller_specs/Cookies.md +57 -0
  14. data/features/controller_specs/README.md +45 -0
  15. data/features/controller_specs/anonymous_controller.feature +378 -0
  16. data/features/controller_specs/bypass_rescue.feature +75 -0
  17. data/features/controller_specs/controller_spec.feature +58 -0
  18. data/features/controller_specs/engine_routes.feature +51 -0
  19. data/features/controller_specs/isolation_from_views.feature +87 -0
  20. data/features/controller_specs/render_views.feature +114 -0
  21. data/features/directory_structure.feature +71 -0
  22. data/features/feature_specs/feature_spec.feature +35 -0
  23. data/features/helper_specs/helper_spec.feature +122 -0
  24. data/features/mailer_specs/url_helpers.feature +38 -0
  25. data/features/matchers/README.md +18 -0
  26. data/features/matchers/new_record_matcher.feature +41 -0
  27. data/features/matchers/redirect_to_matcher.feature +40 -0
  28. data/features/matchers/relation_match_array.feature +27 -0
  29. data/features/matchers/render_template_matcher.feature +49 -0
  30. data/features/mocks/mock_model.feature +147 -0
  31. data/features/mocks/stub_model.feature +58 -0
  32. data/features/model_specs/README.md +21 -0
  33. data/features/model_specs/errors_on.feature +51 -0
  34. data/features/model_specs/records.feature +27 -0
  35. data/features/model_specs/transactional_examples.feature +109 -0
  36. data/features/request_specs/request_spec.feature +49 -0
  37. data/features/routing_specs/README.md +16 -0
  38. data/features/routing_specs/be_routable_matcher.feature +80 -0
  39. data/features/routing_specs/engine_routes.feature +38 -0
  40. data/features/routing_specs/named_routes.feature +18 -0
  41. data/features/routing_specs/route_to_matcher.feature +90 -0
  42. data/features/step_definitions/additional_cli_steps.rb +4 -0
  43. data/features/step_definitions/model_steps.rb +3 -0
  44. data/features/support/capybara.rb +7 -0
  45. data/features/support/env.rb +53 -0
  46. data/features/support/rails_versions.rb +4 -0
  47. data/features/support/rubinius.rb +6 -0
  48. data/features/view_specs/inferred_controller_path.feature +45 -0
  49. data/features/view_specs/stub_template.feature +51 -0
  50. data/features/view_specs/view_spec.feature +206 -0
  51. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  52. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +2 -21
  53. data/lib/generators/rspec/integration/integration_generator.rb +2 -3
  54. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  55. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +4 -4
  56. data/lib/generators/rspec/scaffold/scaffold_generator.rb +2 -3
  57. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +16 -16
  58. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +2 -2
  59. data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
  60. data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -2
  61. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +7 -7
  62. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  63. data/lib/rspec/rails.rb +0 -5
  64. data/lib/rspec/rails/adapters.rb +5 -12
  65. data/lib/rspec/rails/example.rb +55 -24
  66. data/lib/rspec/rails/example/controller_example_group.rb +7 -31
  67. data/lib/rspec/rails/example/view_example_group.rb +0 -3
  68. data/lib/rspec/rails/matchers.rb +1 -2
  69. data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
  70. data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
  71. data/lib/rspec/rails/matchers/be_valid.rb +1 -1
  72. data/lib/rspec/rails/matchers/have_rendered.rb +1 -1
  73. data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
  74. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  75. data/lib/rspec/rails/matchers/routing_matchers.rb +6 -10
  76. data/lib/rspec/rails/mocks.rb +5 -41
  77. data/lib/rspec/rails/tasks/rspec.rake +5 -12
  78. data/lib/rspec/rails/vendor/capybara.rb +4 -35
  79. data/lib/rspec/rails/version.rb +1 -1
  80. data/spec/generators/rspec/controller/controller_generator_spec.rb +97 -0
  81. data/spec/generators/rspec/helper/helper_generator_spec.rb +30 -0
  82. data/spec/generators/rspec/install/install_generator_spec.rb +30 -0
  83. data/spec/generators/rspec/integration/integration_generator_spec.rb +44 -0
  84. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +48 -0
  85. data/spec/generators/rspec/model/model_generator_spec.rb +52 -0
  86. data/spec/generators/rspec/observer/observer_generator_spec.rb +21 -0
  87. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +138 -0
  88. data/spec/generators/rspec/view/view_generator_spec.rb +41 -0
  89. data/spec/rspec/rails/assertion_adapter_spec.rb +28 -0
  90. data/spec/rspec/rails/assertion_delegator_spec.rb +43 -0
  91. data/spec/rspec/rails/configuration_spec.rb +26 -0
  92. data/spec/rspec/rails/deprecations_spec.rb +18 -0
  93. data/spec/rspec/rails/example/controller_example_group_spec.rb +100 -0
  94. data/spec/rspec/rails/example/feature_example_group_spec.rb +56 -0
  95. data/spec/rspec/rails/example/helper_example_group_spec.rb +66 -0
  96. data/spec/rspec/rails/example/mailer_example_group_spec.rb +21 -0
  97. data/spec/rspec/rails/example/model_example_group_spec.rb +15 -0
  98. data/spec/rspec/rails/example/request_example_group_spec.rb +17 -0
  99. data/spec/rspec/rails/example/routing_example_group_spec.rb +32 -0
  100. data/spec/rspec/rails/example/view_example_group_spec.rb +220 -0
  101. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
  102. data/spec/rspec/rails/extensions/active_record/base_spec.rb +42 -0
  103. data/spec/rspec/rails/fixture_support_spec.rb +17 -0
  104. data/spec/rspec/rails/matchers/be_a_new_spec.rb +142 -0
  105. data/spec/rspec/rails/matchers/be_new_record_spec.rb +33 -0
  106. data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
  107. data/spec/rspec/rails/matchers/be_valid_spec.rb +44 -0
  108. data/spec/rspec/rails/matchers/has_spec.rb +29 -0
  109. data/spec/rspec/rails/matchers/have_rendered_spec.rb +93 -0
  110. data/spec/rspec/rails/matchers/redirect_to_spec.rb +80 -0
  111. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +31 -0
  112. data/spec/rspec/rails/matchers/route_to_spec.rb +151 -0
  113. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +22 -0
  114. data/spec/rspec/rails/mocks/mock_model_spec.rb +378 -0
  115. data/spec/rspec/rails/mocks/stub_model_spec.rb +154 -0
  116. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +32 -0
  117. data/spec/rspec/rails/view_rendering_spec.rb +111 -0
  118. data/spec/spec_helper.rb +35 -0
  119. data/spec/support/ar_classes.rb +42 -0
  120. data/spec/support/helpers.rb +20 -0
  121. data/spec/support/matchers.rb +9 -0
  122. data/spec/support/null_object.rb +6 -0
  123. metadata +229 -42
  124. metadata.gz.sig +0 -0
  125. data/lib/autotest/rails_rspec2.rb +0 -91
  126. data/lib/rspec/rails/infer_type_configuration.rb +0 -26
  127. data/lib/rspec/rails/matchers/have_extension.rb +0 -36
  128. data/lib/rspec/rails/module_inclusion.rb +0 -19
@@ -55,53 +55,29 @@ module RSpec::Rails
55
55
  # # ....
56
56
  # end
57
57
  def controller(base_class = nil, &body)
58
- root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
59
58
  base_class ||= RSpec.configuration.infer_base_class_for_anonymous_controllers? ?
60
59
  controller_class :
61
- root_controller
62
- base_class ||= root_controller
60
+ ApplicationController
63
61
 
64
- new_controller_class = Class.new(base_class) do
62
+ metadata[:example_group][:described_class] = Class.new(base_class) do
65
63
  def self.name; "AnonymousController"; end
66
64
  end
67
- new_controller_class.class_eval(&body)
68
-
69
- (class << self; self; end).__send__(:define_method, :controller_class) { new_controller_class }
70
- metadata[:example_group].delete(:described_class)
71
- metadata[:example_group].extend DescribedClassDeprecation.new(new_controller_class)
65
+ metadata[:example_group][:described_class].class_eval(&body)
72
66
 
67
+ orig_routes = nil
73
68
  before do
74
- @orig_routes = self.routes
69
+ orig_routes = self.routes
75
70
  self.routes = ActionDispatch::Routing::RouteSet.new.tap { |r|
76
71
  r.draw { resources :anonymous }
77
72
  }
78
73
  end
79
74
 
80
75
  after do
81
- self.routes = @orig_routes
76
+ self.routes = orig_routes
82
77
  @orig_routes = nil
83
78
  end
84
79
  end
85
80
 
86
- class DescribedClassDeprecation < Module
87
- def initialize(value)
88
- module_eval do
89
- define_method :store_computed do |key|
90
- return super(key) unless key == :described_class
91
-
92
- RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/,''))
93
- |In RSpec 3, the `controller { }` macro no longer changes
94
- |`described_class` to refer to the generated anonymous controller
95
- |class. Instead of `described_class`, use `controller_class` to
96
- |access the generated anonymous class.
97
- |(`described_class` called from #{::RSpec::CallerFilter.first_non_rspec_line}.)
98
- EOS
99
- store(:described_class, value)
100
- end
101
- end
102
- end
103
- end
104
-
105
81
  # Specifies the routeset that will be used for the example group. This
106
82
  # is most useful when testing Rails engines.
107
83
  #
@@ -158,7 +134,7 @@ module RSpec::Rails
158
134
  # If method is a named_route, delegates to the RouteSet associated with
159
135
  # this controller.
160
136
  def method_missing(method, *args, &block)
161
- if @routes && @routes.named_routes.helpers.include?(method)
137
+ if defined?(@routes) && @routes.named_routes.helpers.include?(method)
162
138
  controller.send(method, *args, &block)
163
139
  elsif defined?(@orig_routes) && @orig_routes && @orig_routes.named_routes.helpers.include?(method)
164
140
  controller.send(method, *args, &block)
@@ -152,9 +152,6 @@ module RSpec::Rails
152
152
  view.lookup_context.prefixes << _controller_path
153
153
  end
154
154
 
155
- # fixes bug with differing formats
156
- view.lookup_context.view_paths.each(&:clear_cache)
157
-
158
155
  controller.controller_path = _controller_path
159
156
  controller.request.path_parameters[:controller] = _controller_path
160
157
  controller.request.path_parameters[:action] = _inferred_action unless _inferred_action =~ /^_/
@@ -1,4 +1,4 @@
1
- require 'rspec/core/deprecation'
1
+ require 'rspec/core/warnings'
2
2
  require 'rspec/expectations'
3
3
 
4
4
  module RSpec::Rails
@@ -22,6 +22,5 @@ require 'rspec/rails/matchers/redirect_to'
22
22
  require 'rspec/rails/matchers/routing_matchers'
23
23
  require 'rspec/rails/matchers/be_new_record'
24
24
  require 'rspec/rails/matchers/be_a_new'
25
- require 'rspec/rails/matchers/have_extension'
26
25
  require 'rspec/rails/matchers/relation_match_array'
27
26
  require 'rspec/rails/matchers/be_valid'
@@ -17,7 +17,7 @@ module RSpec::Rails::Matchers
17
17
  #
18
18
  # it "assigns a new Thing with the submitted attributes" do
19
19
  # post :create, :thing => { :name => "Illegal Value" }
20
- # assigns(:thing).should be_a_new(Thing).with(:name => nil)
20
+ # expect(assigns).to(:thing) be_a_new(Thing).with(:name => nil)
21
21
  # end
22
22
  def with(expected_attributes)
23
23
  attributes.merge!(expected_attributes)
@@ -20,7 +20,7 @@ module RSpec::Rails::Matchers
20
20
  # @example
21
21
  #
22
22
  # get :new
23
- # assigns(:thing).should be_new_record
23
+ # expect(assigns(:thing)).to be_new_record
24
24
  def be_new_record
25
25
  BeANewRecord.new
26
26
  end
@@ -33,7 +33,7 @@ module RSpec::Rails::Matchers
33
33
  # @example
34
34
  #
35
35
  # thing = Thing.new
36
- # thing.should be_valid
36
+ # expect(thing).to be_valid
37
37
  def be_valid(*args)
38
38
  BeValid.new(*args)
39
39
  end
@@ -30,7 +30,7 @@ module RSpec::Rails::Matchers
30
30
  #
31
31
  # @example
32
32
  #
33
- # response.should have_rendered("new")
33
+ # expect(response).to have_rendered("new")
34
34
  def have_rendered(options, message=nil)
35
35
  RenderTemplateMatcher.new(self, options, message)
36
36
  end
@@ -29,7 +29,7 @@ module RSpec::Rails::Matchers
29
29
  #
30
30
  # @example
31
31
  #
32
- # response.should redirect_to(:action => "new")
32
+ # expect(response).to redirect_to(:action => "new")
33
33
  def redirect_to(target)
34
34
  RedirectTo.new(self, target)
35
35
  end
@@ -1,3 +1,3 @@
1
1
  if defined?(ActiveRecord::Relation)
2
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::MatchArray)
2
+ RSpec::Matchers::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::MatchArray)
3
3
  end
@@ -14,7 +14,7 @@ module RSpec::Rails::Matchers
14
14
  @expected.merge!(:controller => controller, :action => action)
15
15
  end
16
16
  end
17
-
17
+
18
18
  # @api private
19
19
  def matches?(verb_to_path_map)
20
20
  @actual = @verb_to_path_map = verb_to_path_map
@@ -35,10 +35,6 @@ module RSpec::Rails::Matchers
35
35
  rescued_exception.message
36
36
  end
37
37
 
38
- def failure_message_for_should_not
39
- "expected #{@actual.inspect} not to route to #{@expected.inspect}"
40
- end
41
-
42
38
  def description
43
39
  "route #{@actual.inspect} to #{@expected.inspect}"
44
40
  end
@@ -49,12 +45,12 @@ module RSpec::Rails::Matchers
49
45
  #
50
46
  # @example
51
47
  #
52
- # { :get => "/things/special" }.should route_to(
48
+ # expect(:get => "/things/special").to route_to(
53
49
  # :controller => "things",
54
50
  # :action => "special"
55
51
  # )
56
52
  #
57
- # { :get => "/things/special" }.should route_to("things#special")
53
+ # expect(:get => "/things/special").to route_to("things#special")
58
54
  #
59
55
  # @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
60
56
  def route_to(*expected)
@@ -93,9 +89,9 @@ module RSpec::Rails::Matchers
93
89
  # @example
94
90
  #
95
91
  # You can use route helpers provided by rspec-rails.
96
- # {:get => "/a/path"}.should be_routable
97
- # {:post => "/another/path"}.should be_routable
98
- # {:put => "/yet/another/path"}.should_not be_routable
92
+ # expect(:get => "/a/path").to be_routable
93
+ # expect(:post => "/another/path").to be_routable
94
+ # expect(:put => "/yet/another/path").to be_routable
99
95
  def be_routable
100
96
  BeRoutableMatcher.new(self)
101
97
  end
@@ -1,5 +1,3 @@
1
- require 'active_support'
2
- require 'active_support/deprecation'
3
1
  require 'active_support/core_ext'
4
2
  require 'active_model'
5
3
 
@@ -31,19 +29,6 @@ module RSpec
31
29
  end
32
30
  end
33
31
 
34
- # Starting with Rails 4.1, ActiveRecord associations are inversible
35
- # by default. This class represents an association from the mocked
36
- # model's perspective.
37
- #
38
- # @private
39
- class Association
40
- attr_accessor :target, :inversed
41
-
42
- def initialize(association_name)
43
- @association_name = association_name
44
- end
45
- end
46
-
47
32
  module ActiveRecordInstanceMethods
48
33
  # Stubs `persisted?` to return `false` and `id` to return `nil`.
49
34
  def destroy
@@ -60,13 +45,6 @@ module RSpec
60
45
  def new_record?
61
46
  !persisted?
62
47
  end
63
-
64
- # Returns an object representing an association from the mocked
65
- # model's perspective. For use by Rails internally only.
66
- def association(association_name)
67
- @associations ||= Hash.new { |h, k| h[k] = Association.new(k) }
68
- @associations[association_name]
69
- end
70
48
  end
71
49
 
72
50
  # Creates a test double representing `string_or_model_class` with common
@@ -87,13 +65,12 @@ module RSpec
87
65
  # * A String representing a Class that extends ActiveModel::Naming
88
66
  # * A Class that extends ActiveModel::Naming
89
67
  def mock_model(string_or_model_class, stubs = {})
90
- RSpec.deprecate("`mock_model`", :replacement => "the `rspec-activemodel-mocks` gem")
91
68
  if String === string_or_model_class
92
69
  if Object.const_defined?(string_or_model_class)
93
70
  model_class = Object.const_get(string_or_model_class)
94
71
  else
95
72
  model_class = Object.const_set(string_or_model_class, Class.new do
96
- extend ::ActiveModel::Naming
73
+ extend ActiveModel::Naming
97
74
  def self.primary_key; :id; end
98
75
  end)
99
76
  end
@@ -101,7 +78,7 @@ module RSpec
101
78
  model_class = string_or_model_class
102
79
  end
103
80
 
104
- unless model_class.kind_of? ::ActiveModel::Naming
81
+ unless model_class.kind_of? ActiveModel::Naming
105
82
  raise ArgumentError.new <<-EOM
106
83
  The mock_model method can only accept as its first argument:
107
84
  * A String representing a Class that does not exist
@@ -123,8 +100,8 @@ EOM
123
100
  m.singleton_class.class_eval do
124
101
  include ActiveModelInstanceMethods
125
102
  include ActiveRecordInstanceMethods if defined?(ActiveRecord)
126
- include ::ActiveModel::Conversion
127
- include ::ActiveModel::Validations
103
+ include ActiveModel::Conversion
104
+ include ActiveModel::Validations
128
105
  end
129
106
  if defined?(ActiveRecord)
130
107
  [:save, :update_attributes, :update].each do |key|
@@ -150,10 +127,6 @@ EOM
150
127
  #{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s)
151
128
  end
152
129
 
153
- def @object.has_attribute?(attr_name)
154
- __model_class_has_column?(attr_name)
155
- end unless #{stubs.has_key?(:has_attribute?)}
156
-
157
130
  def @object.respond_to?(method_name, include_private=false)
158
131
  __model_class_has_column?(method_name) ? true : super
159
132
  end unless #{stubs.has_key?(:respond_to?)}
@@ -235,7 +208,6 @@ EOM
235
208
  # stub_model(Person, :to_param => 37)
236
209
  # stub_model(Person) {|person| person.first_name = "David"}
237
210
  def stub_model(model_class, stubs={})
238
- RSpec.deprecate("`stub_model`", :replacement => "the `rspec-activemodel-mocks` gem")
239
211
  model_class.new.tap do |m|
240
212
  m.extend ActiveModelStubExtensions
241
213
  if defined?(ActiveRecord) && model_class < ActiveRecord::Base
@@ -273,12 +245,4 @@ EOM
273
245
  end
274
246
  end
275
247
 
276
- # We need to check if rspec-activemodel-mocks is in use on this side due
277
- # to Rails defaults. Because rspec-activemodel-mocks does not depend on
278
- # rspec-rails, bundler is likely to require rspec-activemodel-mocks before
279
- # rspec-rails when Bundler.require is performed. This will result in the
280
- # user still getting a deprecation message even when they are doing
281
- # everything right.
282
- unless defined?(RSpec::ActiveModel::Mocks::Mocks)
283
- RSpec.configuration.include RSpec::Rails::Mocks
284
- end
248
+ RSpec.configuration.include RSpec::Rails::Mocks
@@ -3,12 +3,14 @@ if default = Rake.application.instance_variable_get('@tasks')['default']
3
3
  default.prerequisites.delete('test')
4
4
  end
5
5
 
6
+ spec_prereq = Rails.configuration.generators.options[:rails][:orm] == :active_record ? "test:prepare" : :noop
7
+ task :noop do; end
6
8
  task :default => :spec
7
9
 
8
10
  task :stats => "spec:statsetup"
9
11
 
10
12
  desc "Run all specs in spec directory (excluding plugin specs)"
11
- RSpec::Core::RakeTask.new(:spec => "spec:prepare")
13
+ RSpec::Core::RakeTask.new(:spec => spec_prereq)
12
14
 
13
15
  namespace :spec do
14
16
  types = begin
@@ -19,18 +21,9 @@ namespace :spec do
19
21
  Hash[dirs.map { |d| [d.split('/').last, d] }]
20
22
  end
21
23
 
22
- task :prepare do
23
- ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
24
- if Rails.configuration.generators.options[:rails][:orm] == :active_record
25
- if ::Rails::VERSION::STRING.to_f < 4.1
26
- Rake::Task["test:prepare"].invoke
27
- end
28
- end
29
- end
30
-
31
24
  types.each do |type, dir|
32
25
  desc "Run the code examples in #{dir}"
33
- RSpec::Core::RakeTask.new(type => "spec:prepare") do |t|
26
+ RSpec::Core::RakeTask.new(type => spec_prereq) do |t|
34
27
  t.pattern = "./#{dir}/**/*_spec.rb"
35
28
  end
36
29
  end
@@ -38,7 +31,7 @@ namespace :spec do
38
31
  # RCov task only enabled for Ruby 1.8
39
32
  if RUBY_VERSION < '1.9'
40
33
  desc "Run all specs with rcov"
41
- RSpec::Core::RakeTask.new(:rcov => "spec:prepare") do |t|
34
+ RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t|
42
35
  t.rcov = true
43
36
  t.pattern = "./spec/**/*_spec.rb"
44
37
  t.rcov_opts = '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-,spec'
@@ -9,42 +9,9 @@ rescue LoadError
9
9
  end
10
10
 
11
11
  if defined?(Capybara)
12
- module RSpec::Rails::DeprecatedCapybaraDSL
13
- include ::Capybara::DSL
14
-
15
- def self.included(mod)
16
- mod.extend(ClassMethods)
17
- super
18
- end
19
-
20
- module ClassMethods
21
- def include(mod)
22
- if mod == ::Capybara::DSL
23
- class_variable_set(:@@_rspec_capybara_included_explicitly, true)
24
- end
25
-
26
- super
27
- end
28
- end
29
-
30
- ::Capybara::DSL.instance_methods(false).each do |method|
31
- # capybara internally calls `page`, skip to avoid a duplicate
32
- # deprecation warning
33
- next if method.to_s == 'page'
34
-
35
- define_method method do |*args, &blk|
36
- unless self.class.class_variable_defined?(:@@_rspec_capybara_included_explicitly)
37
- RSpec.deprecate "Using the capybara method `#{method}` in controller specs",
38
- :replacement => "feature specs (spec/features)"
39
- end
40
- super(*args, &blk)
41
- end
42
- end
43
- end
44
-
45
12
  RSpec.configure do |c|
46
13
  if defined?(Capybara::DSL)
47
- c.include ::RSpec::Rails::DeprecatedCapybaraDSL, :type => :controller
14
+ c.include Capybara::DSL, :type => :controller
48
15
  c.include Capybara::DSL, :type => :feature
49
16
  end
50
17
 
@@ -53,7 +20,9 @@ if defined?(Capybara)
53
20
  c.include Capybara::RSpecMatchers, :type => :helper
54
21
  c.include Capybara::RSpecMatchers, :type => :mailer
55
22
  c.include Capybara::RSpecMatchers, :type => :controller
56
- c.include Capybara::RSpecMatchers, :type => :feature
23
+ c.include Capybara::RSpecMatchers, :example_group => {
24
+ :file_path => c.escaped_path(%w[spec features])
25
+ }
57
26
  end
58
27
 
59
28
  unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module Version
4
- STRING = '2.99.0'
4
+ STRING = '3.0.0.beta1'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ # Generators are not automatically loaded by Rails
4
+ require 'generators/rspec/controller/controller_generator'
5
+
6
+ describe Rspec::Generators::ControllerGenerator do
7
+ # Tell the generator where to put its output (what it thinks of as Rails.root)
8
+ destination File.expand_path("../../../../../tmp", __FILE__)
9
+
10
+ before { prepare_destination }
11
+
12
+ describe 'controller specs' do
13
+ subject { file('spec/controllers/posts_controller_spec.rb') }
14
+ describe 'generated by default' do
15
+ before do
16
+ run_generator %w(posts)
17
+ end
18
+
19
+ describe 'the spec' do
20
+ it { should exist }
21
+ it { should contain(/require 'spec_helper'/) }
22
+ it { should contain(/describe PostsController/) }
23
+ end
24
+ end
25
+ describe 'skipped with a flag' do
26
+ before do
27
+ run_generator %w(posts --no-controller_specs)
28
+ end
29
+ it { should_not exist }
30
+ end
31
+ end
32
+
33
+ describe 'view specs' do
34
+ describe 'are not generated' do
35
+ describe 'with no-view-spec flag' do
36
+ before do
37
+ run_generator %w(posts index show --no-view-specs)
38
+ end
39
+ describe 'index.html.erb' do
40
+ subject { file('spec/views/posts/index.html.erb_spec.rb') }
41
+ it { should_not exist }
42
+ end
43
+ end
44
+ describe 'with no actions' do
45
+ before do
46
+ run_generator %w(posts)
47
+ end
48
+ describe 'index.html.erb' do
49
+ subject { file('spec/views/posts/index.html.erb_spec.rb') }
50
+ it { should_not exist }
51
+ end
52
+ end
53
+
54
+ describe 'with --no-template-engine' do
55
+ before do
56
+ run_generator %w(posts index --no-template-engine)
57
+ end
58
+
59
+ describe 'index.html.erb' do
60
+ subject { file('spec/views/posts/index.html._spec.rb') }
61
+ it { should_not exist }
62
+ end
63
+ end
64
+ end
65
+
66
+ describe 'are generated' do
67
+ describe 'with default template engine' do
68
+ before do
69
+ run_generator %w(posts index show)
70
+ end
71
+ describe 'index.html.erb' do
72
+ subject { file('spec/views/posts/index.html.erb_spec.rb') }
73
+ it { should exist }
74
+ it { should contain(/require 'spec_helper'/) }
75
+ it { should contain(/describe "posts\/index.html.erb"/) }
76
+ end
77
+ describe 'show.html.erb' do
78
+ subject { file('spec/views/posts/show.html.erb_spec.rb') }
79
+ it { should exist }
80
+ it { should contain(/require 'spec_helper'/) }
81
+ it { should contain(/describe "posts\/show.html.erb"/) }
82
+ end
83
+ end
84
+ describe 'with haml' do
85
+ before do
86
+ run_generator %w(posts index --template_engine haml)
87
+ end
88
+ describe 'index.html.haml' do
89
+ subject { file('spec/views/posts/index.html.haml_spec.rb') }
90
+ it { should exist }
91
+ it { should contain(/require 'spec_helper'/) }
92
+ it { should contain(/describe "posts\/index.html.haml"/) }
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end