2017-06-27 13:14:50 -04:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2017-06-27 13:14:50 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-02-28 19:11:41 -05:00
|
|
|
RSpec.describe 'Capybara RSpec Matchers', type: :feature do
|
2017-06-27 13:14:50 -04:00
|
|
|
context "after called on session" do
|
|
|
|
it "HaveSelector should allow getting a description of the matcher" do
|
|
|
|
visit('/with_html')
|
|
|
|
matcher = have_selector(:css, 'h2.head', minimum: 3)
|
|
|
|
expect(page).to matcher
|
|
|
|
expect { matcher.description }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it "HaveText should allow getting a description" do
|
|
|
|
visit('/with_html')
|
|
|
|
matcher = have_text("Lorem")
|
|
|
|
expect(page).to matcher
|
|
|
|
expect { matcher.description }.not_to raise_error
|
|
|
|
end
|
2018-02-28 15:54:18 -05:00
|
|
|
|
|
|
|
it "should produce the same error for .to have_no_xxx and .not_to have_xxx" do
|
|
|
|
visit('/with_html')
|
|
|
|
not_to_msg = error_msg_for { expect(page).not_to have_selector(:css, '#referrer') }
|
|
|
|
have_no_msg = error_msg_for { expect(page).to have_no_selector(:css, '#referrer') }
|
|
|
|
expect(not_to_msg).to eq have_no_msg
|
|
|
|
|
|
|
|
not_to_msg = error_msg_for { expect(page).not_to have_text('This is a test') }
|
|
|
|
have_no_msg = error_msg_for { expect(page).to have_no_text('This is a test') }
|
|
|
|
expect(not_to_msg).to eq have_no_msg
|
|
|
|
end
|
2017-06-27 13:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "after called on element" do
|
|
|
|
it "HaveSelector should allow getting a description" do
|
|
|
|
visit('/with_html')
|
|
|
|
el = find(:css, '#first')
|
|
|
|
matcher = have_selector(:css, 'a#foo')
|
|
|
|
expect(el).to matcher
|
|
|
|
expect { matcher.description }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it "MatchSelector should allow getting a description" do
|
|
|
|
visit('/with_html')
|
|
|
|
el = find(:css, '#first')
|
|
|
|
matcher = match_selector(:css, '#first')
|
|
|
|
expect(el).to matcher
|
|
|
|
expect { matcher.description }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it "HaveText should allow getting a description" do
|
|
|
|
visit('/with_html')
|
|
|
|
el = find(:css, '#first')
|
|
|
|
matcher = have_text("Lorem")
|
|
|
|
expect(el).to matcher
|
|
|
|
expect { matcher.description }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2018-02-28 15:54:18 -05:00
|
|
|
|
|
|
|
def error_msg_for(&block)
|
2018-02-28 19:11:41 -05:00
|
|
|
expect(&block).to(raise_error { |e| return e.message })
|
2018-02-28 15:54:18 -05:00
|
|
|
end
|
2018-02-28 19:11:41 -05:00
|
|
|
end
|