2017-03-03 16:06:07 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2017-03-03 16:06:07 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/minitest'
|
|
|
|
|
|
|
|
class MinitestTest < Minitest::Test
|
|
|
|
include Capybara::DSL
|
|
|
|
include Capybara::Minitest::Assertions
|
|
|
|
|
|
|
|
def setup
|
|
|
|
visit('/form')
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Capybara.reset_sessions!
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_text
|
2020-06-15 09:52:04 -04:00
|
|
|
assert_text('Form', normalize_ws: false)
|
2017-03-03 16:06:07 -05:00
|
|
|
assert_no_text('Not on the page')
|
|
|
|
refute_text('Also Not on the page')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_title
|
|
|
|
visit('/with_title')
|
|
|
|
assert_title('Test Title')
|
|
|
|
assert_no_title('Not the title')
|
|
|
|
refute_title('Not the title')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_current_path
|
|
|
|
assert_current_path('/form')
|
2020-10-06 01:59:25 -04:00
|
|
|
assert_current_path('/form') { |url| url.query.nil? }
|
2017-03-03 16:06:07 -05:00
|
|
|
assert_no_current_path('/not_form')
|
|
|
|
refute_current_path('/not_form')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_xpath
|
|
|
|
assert_xpath('.//select[@id="form_title"]')
|
2018-07-10 17:18:39 -04:00
|
|
|
assert_xpath('.//select', count: 1) { |el| el[:id] == 'form_title' }
|
2017-03-03 16:06:07 -05:00
|
|
|
assert_no_xpath('.//select[@id="not_form_title"]')
|
2018-07-10 17:18:39 -04:00
|
|
|
assert_no_xpath('.//select') { |el| el[:id] == 'not_form_title' }
|
2017-03-03 16:06:07 -05:00
|
|
|
refute_xpath('.//select[@id="not_form_title"]')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_css
|
|
|
|
assert_css('select#form_title')
|
|
|
|
assert_no_css('select#not_form_title')
|
|
|
|
end
|
|
|
|
|
2018-07-23 14:17:07 -04:00
|
|
|
def test_assert_selector
|
|
|
|
assert_selector(:css, 'select#form_title')
|
|
|
|
assert_selector(:xpath, './/select[@id="form_title"]')
|
|
|
|
assert_no_selector(:css, 'select#not_form_title')
|
|
|
|
assert_no_selector(:xpath, './/select[@id="not_form_title"]')
|
|
|
|
refute_selector(:css, 'select#not_form_title')
|
|
|
|
end
|
|
|
|
|
2017-03-03 16:06:07 -05:00
|
|
|
def test_assert_link
|
|
|
|
visit('/with_html')
|
|
|
|
assert_link('A link')
|
2018-02-28 19:11:41 -05:00
|
|
|
assert_link(count: 1) { |el| el.text == 'A link' }
|
2017-03-03 16:06:07 -05:00
|
|
|
assert_no_link('Not on page')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_button
|
|
|
|
assert_button('fresh_btn')
|
2018-02-28 19:11:41 -05:00
|
|
|
assert_button(count: 1) { |el| el[:id] == 'fresh_btn' }
|
2017-03-03 16:06:07 -05:00
|
|
|
assert_no_button('not_btn')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_field
|
|
|
|
assert_field('customer_email')
|
|
|
|
assert_no_field('not_on_the_form')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_select
|
|
|
|
assert_select('form_title')
|
|
|
|
assert_no_select('not_form_title')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_checked_field
|
|
|
|
assert_checked_field('form_pets_dog')
|
|
|
|
assert_no_checked_field('form_pets_cat')
|
|
|
|
refute_checked_field('form_pets_snake')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_unchecked_field
|
|
|
|
assert_unchecked_field('form_pets_cat')
|
|
|
|
assert_no_unchecked_field('form_pets_dog')
|
|
|
|
refute_unchecked_field('form_pets_snake')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_table
|
|
|
|
visit('/tables')
|
|
|
|
assert_table('agent_table')
|
|
|
|
assert_no_table('not_on_form')
|
|
|
|
refute_table('not_on_form')
|
|
|
|
end
|
|
|
|
|
2017-12-12 18:52:34 -05:00
|
|
|
def test_assert_all_of_selectors
|
|
|
|
assert_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_none_of_selectors
|
|
|
|
assert_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
|
|
|
end
|
|
|
|
|
2018-10-23 13:02:34 -04:00
|
|
|
def test_assert_any_of_selectors
|
|
|
|
assert_any_of_selectors(:css, 'input#not_on_page', 'select#form_other_title')
|
|
|
|
end
|
|
|
|
|
2017-03-03 16:06:07 -05:00
|
|
|
def test_assert_matches_selector
|
|
|
|
assert_matches_selector(find(:field, 'customer_email'), :field, 'customer_email')
|
|
|
|
assert_not_matches_selector(find(:select, 'form_title'), :field, 'customer_email')
|
|
|
|
refute_matches_selector(find(:select, 'form_title'), :field, 'customer_email')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_matches_css
|
|
|
|
assert_matches_css(find(:select, 'form_title'), 'select#form_title')
|
|
|
|
refute_matches_css(find(:select, 'form_title'), 'select#form_other_title')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_matches_xpath
|
|
|
|
assert_matches_xpath(find(:select, 'form_title'), './/select[@id="form_title"]')
|
|
|
|
refute_matches_xpath(find(:select, 'form_title'), './/select[@id="form_other_title"]')
|
|
|
|
end
|
2018-06-20 14:43:21 -04:00
|
|
|
|
2018-12-06 14:12:18 -05:00
|
|
|
def test_assert_matches_style
|
2018-06-20 14:43:21 -04:00
|
|
|
skip "Rack test doesn't support style" if Capybara.current_driver == :rack_test
|
|
|
|
visit('/with_html')
|
2018-12-06 14:12:18 -05:00
|
|
|
assert_matches_style(find(:css, '#second'), display: 'inline')
|
2018-06-20 14:43:21 -04:00
|
|
|
end
|
2019-05-28 15:20:38 -04:00
|
|
|
|
|
|
|
def test_assert_ancestor
|
|
|
|
option = find(:option, 'Finnish')
|
|
|
|
assert_ancestor(option, :css, '#form_locale')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_sibling
|
|
|
|
option = find(:css, '#form_title').find(:option, 'Mrs')
|
|
|
|
assert_sibling(option, :option, 'Mr')
|
|
|
|
end
|
2017-03-03 16:06:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe 'capybara/minitest' do
|
|
|
|
before do
|
|
|
|
Capybara.current_driver = :rack_test
|
|
|
|
Capybara.app = TestApp
|
|
|
|
end
|
|
|
|
|
2018-08-14 23:20:44 -04:00
|
|
|
after do
|
|
|
|
Capybara.use_default_driver
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should support minitest' do
|
2017-03-03 16:06:07 -05:00
|
|
|
output = StringIO.new
|
|
|
|
reporter = Minitest::SummaryReporter.new(output)
|
|
|
|
reporter.start
|
|
|
|
MinitestTest.run reporter, {}
|
|
|
|
reporter.report
|
2020-10-06 01:59:25 -04:00
|
|
|
expect(output.string).to include('22 runs, 53 assertions, 0 failures, 0 errors, 1 skips')
|
2017-03-03 16:06:07 -05:00
|
|
|
end
|
|
|
|
end
|