-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate with ActionDispatch::SystemTest (#1813)
- Loading branch information
Sam Phippen
authored
Aug 26, 2017
1 parent
5d93b79
commit 2fb410b
Showing
10 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
RSpec **does not** use your `ApplicationSystemTestCase` helper. Instead it uses | ||
the default `driven_by(:selenium)` from Rails. If you want to override this | ||
behaviour you can call `driven_by` manually in a test. | ||
|
||
|
||
@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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |