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'
|
|
|
|
require 'capybara/minitest/spec'
|
|
|
|
|
|
|
|
class MinitestSpecTest < Minitest::Spec
|
|
|
|
include ::Capybara::DSL
|
|
|
|
include ::Capybara::Minitest::Assertions
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit('/form')
|
|
|
|
end
|
2018-06-19 16:57:42 -04:00
|
|
|
|
2017-03-03 16:06:07 -05:00
|
|
|
after do
|
|
|
|
Capybara.reset_sessions!
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports text expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_text('Form', minimum: 1)
|
|
|
|
page.wont_have_text('Not a form')
|
|
|
|
form = find(:css, 'form', text: 'Title')
|
|
|
|
form.must_have_text('Customer Email')
|
|
|
|
form.wont_have_text('Some other email')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports current_path expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_current_path('/form')
|
|
|
|
page.wont_have_current_path('/form2')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports title expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
visit('/with_title')
|
|
|
|
page.must_have_title('Test Title')
|
|
|
|
page.wont_have_title('Not the title')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports xpath expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_xpath('.//input[@id="customer_email"]')
|
|
|
|
page.wont_have_xpath('.//select[@id="not_form_title"]')
|
2018-07-10 17:18:39 -04:00
|
|
|
page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == 'not_customer_email' }
|
2017-05-28 11:54:55 -04:00
|
|
|
select = find(:select, 'form_title')
|
|
|
|
select.must_have_xpath('.//option[@class="title"]')
|
2018-02-28 19:11:41 -05:00
|
|
|
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
|
2017-05-28 11:54:55 -04:00
|
|
|
select.wont_have_xpath('.//input[@id="customer_email"]')
|
2017-03-03 16:06:07 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'support css expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_css('input#customer_email')
|
|
|
|
page.wont_have_css('select#not_form_title')
|
|
|
|
el = find(:select, 'form_title')
|
|
|
|
el.must_have_css('option.title')
|
|
|
|
el.wont_have_css('input#customer_email')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports link expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
visit('/with_html')
|
|
|
|
page.must_have_link('A link')
|
|
|
|
page.wont_have_link('Not on page')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports button expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_button('fresh_btn')
|
|
|
|
page.wont_have_button('not_btn')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports field expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_field('customer_email')
|
|
|
|
page.wont_have_field('not_on_the_form')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports select expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_select('form_title')
|
|
|
|
page.wont_have_select('not_form_title')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports checked_field expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_checked_field('form_pets_dog')
|
|
|
|
page.wont_have_checked_field('form_pets_cat')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports unchecked_field expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
page.must_have_unchecked_field('form_pets_cat')
|
|
|
|
page.wont_have_unchecked_field('form_pets_dog')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports table expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
visit('/tables')
|
|
|
|
page.must_have_table('agent_table')
|
|
|
|
page.wont_have_table('not_on_form')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports all_of_selectors expectations' do
|
2017-12-12 18:52:34 -05:00
|
|
|
page.must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports none_of_selectors expectations' do
|
2017-12-12 18:52:34 -05:00
|
|
|
page.must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
|
|
|
end
|
|
|
|
|
2018-10-23 13:02:34 -04:00
|
|
|
it 'supports any_of_selectors expectations' do
|
|
|
|
page.must_have_any_of_selectors(:css, 'select#form_other_title', 'input#not_on_page')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports match_selector expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
find(:field, 'customer_email').must_match_selector(:field, 'customer_email')
|
|
|
|
find(:select, 'form_title').wont_match_selector(:field, 'customer_email')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports match_css expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
find(:select, 'form_title').must_match_css('select#form_title')
|
|
|
|
find(:select, 'form_title').wont_match_css('select#form_other_title')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports match_xpath expectations' do
|
2017-03-03 16:06:07 -05:00
|
|
|
find(:select, 'form_title').must_match_xpath('.//select[@id="form_title"]')
|
|
|
|
find(:select, 'form_title').wont_match_xpath('.//select[@id="not_on_page"]')
|
|
|
|
end
|
2017-06-14 14:57:22 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'handles failures' do
|
2017-06-14 14:57:22 -04:00
|
|
|
page.must_have_select('non_existing_form_title')
|
|
|
|
end
|
2018-06-20 14:43:21 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'supports style expectations' do
|
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
|
|
|
find(:css, '#second').must_match_style('display' => 'inline')
|
2018-06-20 14:43:21 -04:00
|
|
|
end
|
2017-03-03 16:06:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe 'capybara/minitest/spec' 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 spec' do
|
2017-03-03 16:06:07 -05:00
|
|
|
output = StringIO.new
|
|
|
|
reporter = Minitest::SummaryReporter.new(output)
|
|
|
|
reporter.start
|
|
|
|
MinitestSpecTest.run reporter, {}
|
|
|
|
reporter.report
|
2018-10-23 13:02:34 -04:00
|
|
|
expect(output.string).to include('20 runs, 42 assertions, 1 failures, 0 errors, 1 skips')
|
2018-02-28 19:11:41 -05:00
|
|
|
# Make sure error messages are displayed
|
2019-04-03 14:42:34 -04:00
|
|
|
expect(output.string).to match(/expected to find select box "non_existing_form_title" .*but there were no matches/)
|
2017-03-03 16:06:07 -05:00
|
|
|
end
|
|
|
|
end
|