Sha256: 0fb2aa48c97285f8b2c857c20336f7de350ae95c7ebdf4e23e63ed328ee36adf

Contents?: true

Size: 1.71 KB

Versions: 8

Compression:

Stored size: 1.71 KB

Contents

require "spec_helper"

describe ElabsMatchers::Matchers::HaveHeader, :type => :feature do
  describe "#have_header" do
    let(:html) { Capybara.string(%Q{<div><h1>Elabs</h1><h2>Bespoke</h2><h3>Development</h3></div>}) }
    subject { html }

    it "returns true if given the content of a h1 tag" do
      should have_header("Elabs")
      expect { should have_header("Development") }.to fail_assertion
    end

    it "returns true if given the content of a h2 tag" do
      should have_header("Bespoke")
    end

    it "returns false if given the content of a h3 tag" do
      should_not have_header("Development")

      expect { should_not have_header("Elabs") }.to fail_assertion
      expect { should_not have_header("Bespoke") }.to fail_assertion
    end

    it "returns false if the content doesn't exist on the page" do
      should_not have_header("Bugs")
    end

    shared_examples "a configured have header matcher" do
      it "returns true if given the content of a h3" do
        should have_header("Development")
        expect { should_not have_header("Development") }.to fail_assertion
      end

      it "returns false if given the content of a h2" do
        should_not have_header("Bespoke")
        expect { should have_header("Bespoke") }.to fail_assertion
      end
    end

    context "configured with a css selector" do
      before { ElabsMatchers.header_selector = "h1,h3" }
      it_behaves_like "a configured have header matcher"
    end

    context "configured with xpath selector" do
      before do
        ElabsMatchers.header_selector_type = :xpath
        ElabsMatchers.header_selector = XPath.descendant(:h1, :h3).to_s
      end

      it_behaves_like "a configured have header matcher"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
elabs_matchers-2.0.1 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-2.0.0 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-1.0.1 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-1.0.0 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-0.0.7 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-0.0.6 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-0.0.5 spec/elabs_matchers/matchers/have_header_spec.rb
elabs_matchers-0.0.4 spec/elabs_matchers/matchers/have_header_spec.rb