File: features_spec.rb

package info (click to toggle)
ruby-capybara 2.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,376 kB
  • ctags: 779
  • sloc: ruby: 12,494; makefile: 4
file content (95 lines) | stat: -rw-r--r-- 2,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true
require 'spec_helper'
require 'capybara/rspec'

RSpec.configuration.before(:each, { file_path: "./spec/rspec/features_spec.rb" } ) do
  @in_filtered_hook = true
end

feature "Capybara's feature DSL" do
  background 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])
      .to eq("Capybara's feature DSL preserves description")
  end

  scenario "allows driver switching", :driver => :selenium do
    expect(Capybara.current_driver).to eq(:selenium)
  end

  scenario "runs background" do
    expect(@in_background).to be_truthy
  end

  scenario "runs hooks filtered by file path" do
    expect(@in_filtered_hook).to be_truthy
  end

  scenario "doesn't pollute the Object namespace" do
    expect(Object.new.respond_to?(:feature, true)).to be_falsey
  end

  feature 'nested features' do
    scenario 'work as expected' do
      visit '/'
      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
    end

    scenario 'have a type of :feature' do
      expect(current_example(self).metadata[:type]).to eq :feature
    end
  end
end

feature "given and given! aliases to let and let!" do
  given(:value) { :available }
  given!(:value_in_background) { :available }

  background do
    expect(value_in_background).to be(:available)
  end

  scenario "given and given! work as intended" do
    expect(value).to be(:available)
    expect(value_in_background).to be(:available)
  end
end

feature "Capybara's feature DSL with driver", :driver => :culerity do
  scenario "switches driver" do
    expect(Capybara.current_driver).to eq(:culerity)
  end
end

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