2016-03-07 16:52:19 -08:00
|
|
|
# frozen_string_literal: true
|
2011-02-11 14:44:58 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/rspec'
|
|
|
|
|
2014-06-20 13:51:28 -07:00
|
|
|
RSpec.configuration.before(:each, { file_path: "./spec/rspec/features_spec.rb" } ) do
|
2011-03-13 14:31:04 +01:00
|
|
|
@in_filtered_hook = true
|
|
|
|
end
|
|
|
|
|
2016-07-22 10:21:24 -07:00
|
|
|
feature "Capybara's feature DSL" do
|
2011-02-11 14:44:58 +01:00
|
|
|
background do
|
|
|
|
@in_background = true
|
|
|
|
end
|
2016-07-22 10:21:24 -07:00
|
|
|
|
2013-11-14 09:43:36 -08:00
|
|
|
def current_example(context)
|
|
|
|
RSpec.respond_to?(:current_example) ? RSpec.current_example : context.example
|
|
|
|
end
|
2011-02-11 14:44:58 +01:00
|
|
|
|
|
|
|
scenario "includes Capybara" do
|
|
|
|
visit('/')
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(page).to have_content('Hello world!')
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
|
|
|
|
2016-07-22 10:21:24 -07:00
|
|
|
scenario "preserves description" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(current_example(self).metadata[:full_description])
|
|
|
|
.to eq("Capybara's feature DSL preserves description")
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario "allows driver switching", :driver => :selenium do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(Capybara.current_driver).to eq(:selenium)
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario "runs background" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(@in_background).to be_truthy
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
2011-03-31 18:05:58 +02:00
|
|
|
|
2011-03-13 14:31:04 +01:00
|
|
|
scenario "runs hooks filtered by file path" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(@in_filtered_hook).to be_truthy
|
2011-03-13 14:31:04 +01:00
|
|
|
end
|
2011-03-31 18:05:58 +02:00
|
|
|
|
2011-03-12 12:38:48 +01:00
|
|
|
scenario "doesn't pollute the Object namespace" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(Object.new.respond_to?(:feature, true)).to be_falsey
|
2011-03-12 12:38:48 +01:00
|
|
|
end
|
2013-07-09 15:58:18 -07:00
|
|
|
|
|
|
|
feature 'nested features' do
|
|
|
|
scenario 'work as expected' do
|
|
|
|
visit '/'
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(page).to have_content 'Hello world!'
|
2013-07-09 15:58:18 -07:00
|
|
|
end
|
|
|
|
|
2013-07-21 23:56:21 +02:00
|
|
|
scenario 'are marked in the metadata as capybara_feature' do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(current_example(self).metadata[:capybara_feature]).to be_truthy
|
2013-07-09 15:58:18 -07:00
|
|
|
end
|
|
|
|
|
2013-07-21 23:56:21 +02:00
|
|
|
scenario 'have a type of :feature' do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(current_example(self).metadata[:type]).to eq :feature
|
2013-07-09 15:58:18 -07:00
|
|
|
end
|
|
|
|
end
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
|
|
|
|
2012-10-03 18:49:44 -04:00
|
|
|
feature "given and given! aliases to let and let!" do
|
|
|
|
given(:value) { :available }
|
|
|
|
given!(:value_in_background) { :available }
|
|
|
|
|
|
|
|
background do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(value_in_background).to be(:available)
|
2012-10-03 18:49:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario "given and given! work as intended" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(value).to be(:available)
|
|
|
|
expect(value_in_background).to be(:available)
|
2012-10-03 18:49:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-11 14:44:58 +01:00
|
|
|
feature "Capybara's feature DSL with driver", :driver => :culerity do
|
|
|
|
scenario "switches driver" do
|
2013-11-14 09:43:36 -08:00
|
|
|
expect(Capybara.current_driver).to eq(:culerity)
|
2011-02-11 14:44:58 +01:00
|
|
|
end
|
|
|
|
end
|
2015-12-15 14:03:59 +00:00
|
|
|
|
|
|
|
if RSpec::Core::Version::STRING.to_f >= 3.0
|
|
|
|
xfeature "if xfeature aliases to pending then" do
|
|
|
|
scenario "this should be 'temporarily disabled with xfeature'" do; end
|
|
|
|
scenario "this also should be 'temporarily disabled with xfeature'" do; end
|
|
|
|
end
|
|
|
|
|
|
|
|
ffeature "if ffeature aliases focused tag then" do
|
|
|
|
scenario "scenario inside this feature has metatag focus tag" do |example|
|
|
|
|
expect(example.metadata[:focus]).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario "other scenarios also has metatag focus tag " do |example|
|
|
|
|
expect(example.metadata[:focus]).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|