Skip to content

Commit 94eb855

Browse files
author
Sam Phippen
committed
WIP: Integrate with ActionDispatch::SystemTest
1 parent 076fe2a commit 94eb855

File tree

7 files changed

+98
-1
lines changed

7 files changed

+98
-1
lines changed

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source "https://rubygems.org"
2+
RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp)
23

34
gemspec
45

@@ -37,9 +38,12 @@ if RUBY_VERSION < '2.0.0'
3738
gem 'mime-types', '< 3'
3839
end
3940

41+
4042
# Capybara versions that support RSpec 3 only support RUBY_VERSION >= 1.9.3
41-
if RUBY_VERSION >= '1.9.3'
43+
if RUBY_VERSION >= '1.9.3' && RAILS_VERSION < '5.1'
4244
gem 'capybara', '~> 2.2.0', :require => false
45+
else
46+
gem 'capybara', '~> 2.13', :require => false
4347
end
4448

4549
# Rack::Cache 1.3.0 requires Ruby >= 2.0.0

Gemfile-rails-dependencies

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ when /master/
1313
gem 'i18n', :git => 'git://github.com/svenfuchs/i18n.git', :branch => 'master'
1414
gem 'sprockets', :git => 'git://github.com/rails/sprockets.git', :branch => 'master'
1515
gem 'sprockets-rails', :git => 'git://github.com/rails/sprockets-rails.git', :branch => 'master'
16+
gem 'puma', :git => 'git://github.com/puma/puma', :branch => 'master'
1617
when /stable$/
1718
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport]
1819
gem_list << 'activejob' if version > '4-1-stable'
1920
gem_list << 'actionview' if version > '4-0-stable'
21+
gem_list << 'puma' if version > '5-0-stable'
22+
2023
gem_list.each do |rails_gem|
2124
gem rails_gem, :git => "git://github.com/rails/rails.git", :branch => version
2225
end
@@ -32,6 +35,10 @@ when nil, false, ""
3235
end
3336
else
3437
gem "rails", version
38+
39+
if version >= '5.1'
40+
gem "puma"
41+
end
3542
end
3643

3744
gem "i18n", '< 0.7.0' if RUBY_VERSION < '1.9.3'

lib/rspec/rails/configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def self.add_test_type_configurations(config)
4848
config.include RSpec::Rails::ViewExampleGroup, :type => :view
4949
config.include RSpec::Rails::FeatureExampleGroup, :type => :feature
5050
config.include RSpec::Rails::Matchers
51+
52+
if ActionPack::VERSION::STRING >= "5.1"
53+
config.include RSpec::Rails::SystemExampleGroup, :type => :system
54+
end
5155
end
5256

5357
# @private

lib/rspec/rails/example.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
require 'rspec/rails/example/model_example_group'
99
require 'rspec/rails/example/job_example_group'
1010
require 'rspec/rails/example/feature_example_group'
11+
if ActionPack::VERSION::STRING >= "5.1"
12+
require 'rspec/rails/example/system_example_group'
13+
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
if ActionPack::VERSION::STRING >= "5.1"
2+
require 'action_dispatch/system_test_case'
3+
module RSpec
4+
module Rails
5+
# @api public
6+
# Container class for request spec functionality.
7+
module SystemExampleGroup
8+
extend ActiveSupport::Concern
9+
include RSpec::Rails::RailsExampleGroup
10+
include ActionDispatch::Integration::Runner
11+
include ActionDispatch::Assertions
12+
include RSpec::Rails::Matchers::RedirectTo
13+
include RSpec::Rails::Matchers::RenderTemplate
14+
include ActionController::TemplateAssertions
15+
16+
include ActionDispatch::IntegrationTest::Behavior
17+
18+
module BlowAwayAfterTeardownHook
19+
def after_teardown
20+
end
21+
end
22+
23+
original_after_teardown = ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
24+
25+
include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
26+
include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
27+
include BlowAwayAfterTeardownHook
28+
29+
# for the SystemTesting Screenshot situation
30+
def passed?
31+
RSpec.current_example.exception.nil?
32+
end
33+
34+
35+
# Delegates to `Rails.application`.
36+
def app
37+
::Rails.application
38+
end
39+
40+
included do
41+
def driven_by(*args, &blk)
42+
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap { |d|
43+
d.use
44+
}
45+
end
46+
47+
def driver
48+
@driver
49+
end
50+
51+
before do
52+
driven_by(:selenium)
53+
@routes = ::Rails.application.routes
54+
end
55+
56+
after do
57+
original_after_teardown.bind(self).call
58+
end
59+
60+
around do |ex|
61+
ex.run
62+
end
63+
end
64+
end
65+
end
66+
end
67+
end

lib/rspec/rails/vendor/capybara.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
RSpec.configure do |c|
1818
if defined?(Capybara::DSL)
1919
c.include Capybara::DSL, :type => :feature
20+
if defined?(ActionPack) && ActionPack::VERSION::STRING >= "5.1"
21+
c.include Capybara::DSL, :type => :system
22+
end
2023
end
2124

2225
if defined?(Capybara::RSpecMatchers)
@@ -25,6 +28,7 @@
2528
c.include Capybara::RSpecMatchers, :type => :mailer
2629
c.include Capybara::RSpecMatchers, :type => :controller
2730
c.include Capybara::RSpecMatchers, :type => :feature
31+
c.include Capybara::RSpecMatchers, :type => :system
2832
end
2933

3034
unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "spec_helper"
2+
3+
module RSpec::Rails
4+
describe SystemExampleGroup do
5+
it_behaves_like "an rspec-rails example group mixin", :system,
6+
'./spec/system/', '.\\spec\\system\\'
7+
end
8+
end

0 commit comments

Comments
 (0)