Skip to content

Commit 53571a4

Browse files
committed
let request specs use integration test services
Rails integration tests have services like assert_select. This makes them available in request specs.
1 parent 9a20df1 commit 53571a4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/rspec/rails/example/request_example_group.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
module RSpec
22
module Rails
3+
# Raises an error if the user tries to call integration test helpers.
4+
# If the helpers are available then this module will be ignored.
5+
module IntegrationHelperWarnings
6+
extend ActiveSupport::Concern
7+
[:assert_select, :url_for, :url_options].each do |name|
8+
define_method(name) { |*| raise "you must upgrade Rails to call #{name}" }
9+
end
10+
end
11+
312
# @api public
413
# Container class for request spec functionality.
514
module RequestExampleGroup
@@ -11,6 +20,12 @@ module RequestExampleGroup
1120
include RSpec::Rails::Matchers::RenderTemplate
1221
include ActionController::TemplateAssertions
1322

23+
begin
24+
include ActionDispatch::IntegrationTest::Behavior
25+
rescue NameError
26+
include IntegrationHelperWarnings
27+
end
28+
1429
# Delegates to `Rails.application`.
1530
def app
1631
::Rails.application

0 commit comments

Comments
 (0)