-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate with ActionDispatch::SystemTest #1813
Changes from all commits
3bf678f
c52bf05
d4b73e6
0373ee7
b2677a7
9785598
0166fb0
dc563b6
cb2596b
3e5ad34
5ce2a4a
dafa01f
e68fe9c
3f14313
c4adf26
4b422bb
bfb8eb7
e05a787
b72cb4a
9e389a8
7aef2ec
f591652
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,17 @@ when /master/ | |
gem 'i18n', :git => 'git://github.com/svenfuchs/i18n.git', :branch => 'master' | ||
gem 'sprockets', :git => 'git://github.com/rails/sprockets.git', :branch => 'master' | ||
gem 'sprockets-rails', :git => 'git://github.com/rails/sprockets-rails.git', :branch => 'master' | ||
if RUBY_VERSION >= "1.9.3" | ||
gem 'puma', :git => 'git://github.com/puma/puma', :branch => 'master' | ||
end | ||
when /stable$/ | ||
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport] | ||
gem_list << 'activejob' if version > '4-1-stable' | ||
gem_list << 'actionview' if version > '4-0-stable' | ||
if RUBY_VERSION >= "1.9.3" | ||
gem_list << 'puma' if version > '5-0-stable' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
gem_list.each do |rails_gem| | ||
gem rails_gem, :git => "git://github.com/rails/rails.git", :branch => version | ||
end | ||
|
@@ -32,6 +39,10 @@ when nil, false, "" | |
end | ||
else | ||
gem "rails", version | ||
|
||
if version >= '5-1-stable' && RUBY_VERSION >= "1.9.3" | ||
gem "puma" | ||
end | ||
end | ||
|
||
gem "i18n", '< 0.7.0' if RUBY_VERSION < '1.9.3' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: System spec | ||
|
||
System specs are RSpec's wrapper around Rails' own | ||
[system tests](http://guides.rubyonrails.org/testing.html#system-testing). | ||
We encourage you to familiarse yourself with their documentation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/familiarse/familiarise/ |
||
|
||
RSpec **does not** use your `ApplicationSystemTestCase` helper. Instead it uses | ||
the default `driven_by(:selenium)` from Rails. If you want to override this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might it be worth us overriding this and defaulting to rack test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strongly disagree, selenium is the default in Rails and so I think it's better to mirror that default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your call, just a suggestion |
||
behaviour you can call `driven_by` manually in a test. | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excess white space, my old nemesis, we meet again. |
||
@system_test | ||
Scenario: System specs | ||
Given a file named "spec/system/widget_system_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe "Widget management", :type => :system do | ||
before do | ||
driven_by(:rack_test) | ||
end | ||
|
||
it "enables me to create widgets" do | ||
visit "/widgets/new" | ||
|
||
fill_in "Name", :with => "My Widget" | ||
click_button "Create Widget" | ||
|
||
expect(page).to have_text("Widget was successfully created.") | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/system/widget_system_spec.rb` | ||
Then the exit status should be 0 | ||
And the output should contain "1 example, 0 failures" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
if ActionPack::VERSION::STRING >= "5.1" | ||
require 'action_dispatch/system_test_case' | ||
module RSpec | ||
module Rails | ||
# @api public | ||
# Container class for system tests | ||
module SystemExampleGroup | ||
extend ActiveSupport::Concern | ||
include RSpec::Rails::RailsExampleGroup | ||
include ActionDispatch::Integration::Runner | ||
include ActionDispatch::Assertions | ||
include RSpec::Rails::Matchers::RedirectTo | ||
include RSpec::Rails::Matchers::RenderTemplate | ||
include ActionController::TemplateAssertions | ||
|
||
include ActionDispatch::IntegrationTest::Behavior | ||
|
||
# @private | ||
module BlowAwayAfterTeardownHook | ||
# @private | ||
def after_teardown | ||
end | ||
end | ||
|
||
original_after_teardown = ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown) | ||
|
||
include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown | ||
include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper | ||
include BlowAwayAfterTeardownHook | ||
|
||
# for the SystemTesting Screenshot situation | ||
def passed? | ||
RSpec.current_example.exception.nil? | ||
end | ||
|
||
# @private | ||
def method_name | ||
[ | ||
self.class.name.underscore, | ||
RSpec.current_example.description.underscore, | ||
rand(1000) | ||
].join("_").gsub(/[\/\.:, ]/, "_") | ||
end | ||
|
||
# Delegates to `Rails.application`. | ||
def app | ||
::Rails.application | ||
end | ||
|
||
included do | ||
attr_reader :driver | ||
|
||
if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=) | ||
ActionDispatch::SystemTesting::Server.silence_puma = true | ||
end | ||
|
||
def initialize(*args, &blk) | ||
super(*args, &blk) | ||
@driver = nil | ||
end | ||
|
||
def driven_by(*args, &blk) | ||
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use) | ||
end | ||
|
||
before do | ||
# A user may have already set the driver, so only default if driver | ||
# is not set | ||
driven_by(:selenium) unless @driver | ||
@routes = ::Rails.application.routes | ||
end | ||
|
||
after do | ||
orig_stdout = $stdout | ||
$stdout = StringIO.new | ||
begin | ||
original_after_teardown.bind(self).call | ||
ensure | ||
myio = $stdout | ||
RSpec.current_example.metadata[:extra_failure_lines] = myio.string | ||
$stdout = orig_stdout | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "spec_helper" | ||
module RSpec::Rails | ||
if defined?(SystemExampleGroup) | ||
RSpec.describe SystemExampleGroup do | ||
it_behaves_like "an rspec-rails example group mixin", :system, | ||
'./spec/system/', '.\\spec\\system\\' | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't bundler automatically work this out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pin to
2.2.0
prevents us from bumping further than the highest2.2.x
rails needs at least2.13
. However, we pin to the earliest version that we support, so this is why this is conditionaled like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍