Permalink
Browse files

Add tests for system testing

* Adds test case test
* Adds driver adapter test
* Adds tests for capybara seleium driver (testing the settings not
actually opening the browser to test capybara w/ selenium because that
would so so so slow)
* Adds tests for rack test driver
* Adds tests for generators
  • Loading branch information...
eileencodes committed Aug 27, 2016
1 parent 4533bb7 commit 9730b1dba6d1bb9684a54915ac3735d9c0eade26
View
@@ -45,6 +45,7 @@ PATH
actionpack (5.1.0.alpha)
actionview (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
capybara (~> 2.7.0)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
@@ -125,6 +126,13 @@ GEM
bunny (2.6.2)
amq-protocol (>= 2.0.1)
byebug (9.0.6)
capybara (2.7.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.2.1)
@@ -356,6 +364,8 @@ GEM
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_dependency "rails-html-sanitizer", "~> 1.0", ">= 1.0.2"
s.add_dependency "rails-dom-testing", "~> 2.0"
s.add_dependency "actionview", version
s.add_dependency "capybara", "~> 2.7.0"
s.add_development_dependency "activemodel", version
end
@@ -33,6 +33,7 @@
require "action_dispatch"
require "active_support/dependencies"
require "active_model"
require "system_test_case"
require "pp" # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
@@ -0,0 +1,26 @@
require 'abstract_unit'
class CapybaraRackTestDriverTest < ActiveSupport::TestCase
def test_default_driver_adapter
assert_kind_of SystemTesting::DriverAdapters::CapybaraRackTestDriver, Rails::SystemTestCase.driver
end
def test_default_settings
assert_equal 'Capybara', Rails::SystemTestCase.driver.useragent
end
def test_setting_useragent
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(
useragent: 'x'
)
assert_equal 'x', Rails::SystemTestCase.driver.useragent
end
def test_does_not_accept_nonsense_kwargs
assert_raises ArgumentError do
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(
made_up_arg: 'x'
)
end
end
end
@@ -0,0 +1,58 @@
require 'abstract_unit'
class CapybaraSeleniumDriverTest < ActiveSupport::TestCase
def setup
Rails::SystemTestCase.driver = :capybara_selenium_driver
end
def test_setting_driver_adapter_to_selenium
assert_kind_of SystemTesting::DriverAdapters::CapybaraSeleniumDriver, Rails::SystemTestCase.driver
end
def test_default_settings
assert_equal :chrome, Rails::SystemTestCase.driver.browser
assert_equal :puma, Rails::SystemTestCase.driver.server
assert_equal 28100, Rails::SystemTestCase.driver.port
assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size
end
def test_setting_browser
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
browser: :firefox
)
assert_equal :firefox, Rails::SystemTestCase.driver.browser
end
def test_setting_server
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
server: :webrick
)
assert_equal :webrick, Rails::SystemTestCase.driver.server
end
def test_setting_port
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
port: 3000
)
assert_equal 3000, Rails::SystemTestCase.driver.port
end
def test_setting_screen_size
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
screen_size: [ 800, 800 ]
)
assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size
end
def test_does_not_accept_nonsense_kwargs
assert_raises ArgumentError do
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
made_up_arg: 'x'
)
end
end
end
@@ -0,0 +1,19 @@
require 'abstract_unit'
class DriverAdapterTest < ActiveSupport::TestCase
test 'only registered adapters are accepted' do
assert_raises(NameError) do
Rails::SystemTestCase.driver = :whatever
end
assert_nothing_raised do
Rails::SystemTestCase.driver = :capybara_selenium_driver
end
end
test 'settings can only be used for the appropriate adapter' do
assert_raises(ArgumentError) do
Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(something: 'test')
end
end
end
@@ -42,6 +42,7 @@
test/helpers
test/mailers
test/integration
test/system
vendor
tmp
tmp/cache
@@ -805,8 +806,26 @@ def test_after_bundle_callback
assert_equal 4, @sequence_step
end
private
def test_system_tests_directory_generated
run_generator
assert_file("test/system/.keep")
assert_directory("test/system")
end
def test_system_tests_are_not_generated_on_system_test_skip
run_generator [destination_root, "--skip-system-test"]
assert_no_directory("test/system")
end
def test_system_tests_are_not_generated_on_test_skip
run_generator [destination_root, "--skip-test"]
assert_no_directory("test/system")
end
private
def stub_rails_application(root)
Rails.application.config.root = root
Rails.application.class.stub(:name, "Myapp") do
@@ -62,6 +62,11 @@ def test_scaffold_on_invoke
assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
end
# System tests
assert_file "test/system/product_lines_test.rb" do |test|
assert_match(/class ProductLinesTest < Rails::SystemTestCase/, test)
end
# Views
assert_no_file "app/views/layouts/product_lines.html.erb"
@@ -0,0 +1,12 @@
require "generators/generators_test_helper"
require "rails/generators/rails/system_test/system_test_generator"
class SystemTestGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
arguments %w(user)
def test_system_test_skeleton_is_created
run_generator
assert_file "test/system/users_test.rb", /class UsersTest < Rails::SystemTestCase/
end
end

0 comments on commit 9730b1d

Please sign in to comment.