From 9ebc5033282d40c73b0286e60217515fd1bb0b5d Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 15 May 2018 12:39:40 -0700 Subject: [PATCH] Cleanup some RSpec tests/settings --- lib/capybara/rspec.rb | 3 +-- lib/capybara/rspec/compound.rb | 4 ++-- lib/capybara/spec/session/body_spec.rb | 22 ++++++++++------------ spec/rspec/features_spec.rb | 16 ++++++---------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/capybara/rspec.rb b/lib/capybara/rspec.rb index 6d5704c8..5347b9d3 100644 --- a/lib/capybara/rspec.rb +++ b/lib/capybara/rspec.rb @@ -20,9 +20,8 @@ RSpec.configure do |config| end end - config.before do + config.before do |example| if self.class.include?(Capybara::DSL) - example = RSpec.current_example Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js] Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver] end diff --git a/lib/capybara/rspec/compound.rb b/lib/capybara/rspec/compound.rb index 5c018a3b..9c4ed5b3 100644 --- a/lib/capybara/rspec/compound.rb +++ b/lib/capybara/rspec/compound.rb @@ -6,7 +6,7 @@ module Capybara include ::RSpec::Matchers::Composable def and(matcher) - Capybara::RSpecMatchers::Compound::And.new(self, matcher) + And.new(self, matcher) end def and_then(matcher) @@ -14,7 +14,7 @@ module Capybara end def or(matcher) - Capybara::RSpecMatchers::Compound::Or.new(self, matcher) + Or.new(self, matcher) end class CapybaraEvaluator diff --git a/lib/capybara/spec/session/body_spec.rb b/lib/capybara/spec/session/body_spec.rb index c7b3d50c..c6dc1097 100644 --- a/lib/capybara/spec/session/body_spec.rb +++ b/lib/capybara/spec/session/body_spec.rb @@ -7,19 +7,17 @@ Capybara::SpecHelper.spec '#body' do expect(@session.body).to include('Hello world!') end - if "".respond_to?(:encoding) - context "encoding of response between ascii and utf8" do - it "should be valid with html entities" do - @session.visit('/with_html_entities') - expect(@session).to have_content('Encoding') # wait for content to appear if visit is async - expect { @session.body.encode!("UTF-8") }.not_to raise_error - end + context "encoding of response between ascii and utf8" do + it "should be valid with html entities" do + @session.visit('/with_html_entities') + expect(@session).to have_content('Encoding') # wait for content to appear if visit is async + expect { @session.body.encode!("UTF-8") }.not_to raise_error + end - it "should be valid without html entities" do - @session.visit('/with_html') - expect(@session).to have_content('This is a test') # wait for content to appear if visit is async - expect { @session.body.encode!("UTF-8") }.not_to raise_error - end + it "should be valid without html entities" do + @session.visit('/with_html') + expect(@session).to have_content('This is a test') # wait for content to appear if visit is async + expect { @session.body.encode!("UTF-8") }.not_to raise_error end end end diff --git a/spec/rspec/features_spec.rb b/spec/rspec/features_spec.rb index 310e21e2..8a2877b5 100644 --- a/spec/rspec/features_spec.rb +++ b/spec/rspec/features_spec.rb @@ -12,17 +12,13 @@ feature "Capybara's feature DSL" do @in_background = true end - def current_example(context) - RSpec.respond_to?(:current_example) ? RSpec.current_example : context.example - end - scenario "includes Capybara" do visit('/') expect(page).to have_content('Hello world!') end - scenario "preserves description" do - expect(current_example(self).metadata[:full_description]) + scenario "preserves description" do |ex| + expect(ex.metadata[:full_description]) .to eq("Capybara's feature DSL preserves description") end @@ -48,12 +44,12 @@ feature "Capybara's feature DSL" do expect(page).to have_content 'Hello world!' end - scenario 'are marked in the metadata as capybara_feature' do - expect(current_example(self).metadata[:capybara_feature]).to be_truthy + scenario 'are marked in the metadata as capybara_feature' do |ex| + expect(ex.metadata[:capybara_feature]).to be_truthy end - scenario 'have a type of :feature' do - expect(current_example(self).metadata[:type]).to eq :feature + scenario 'have a type of :feature' do |ex| + expect(ex.metadata[:type]).to eq :feature end end end