Sha256: 5dd5d266ff503cd24887cfd07f79fc4215b11c2fb96c2f0043bb48c8772321bf

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

require "spec_helper"

describe ElabsMatchers::Matchers::HaveImage, :type => :feature do
  describe "#have_image" do
    subject { Capybara.string("<div>" + html + "</div>") }

    shared_examples "a have image matcher" do
      it "returns true if the image exists on the page" do
        should have_image("Logo")
        expect { should have_image("Avatar") }.to fail_assertion
      end

      it "returns false if the image doesn't exist on the page" do
        should_not have_image("Avatar")
        expect { should_not have_image("Logo") }.to fail_assertion
      end
    end

    context "with default configuration" do
      it_behaves_like "a have image matcher" do
        let(:html) { %Q{<img src="logo.png" alt="Logo" />} }
      end
    end

    context "configured with css selector" do
      before do
        ElabsMatchers.image_selector_type = :css
        ElabsMatchers.image_selector = lambda { |src| "img[class='#{src}']" }
      end

      it_behaves_like "a have image matcher" do
        let(:html) { %Q{<img src="logo.png" class="Logo" />} }
      end
    end

    context "configured with xpath selector" do
      before do
        ElabsMatchers.image_selector_type = :xpath
        ElabsMatchers.image_selector = lambda do |src|
          "//img[@class='#{src}']"
        end
      end

      it_behaves_like "a have image matcher" do
        let(:html) { %Q{<img src="logo.png" class="Logo" />} }
      end
    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_image_spec.rb
elabs_matchers-2.0.0 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-1.0.1 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-1.0.0 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-0.0.7 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-0.0.6 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-0.0.5 spec/elabs_matchers/matchers/have_image_spec.rb
elabs_matchers-0.0.4 spec/elabs_matchers/matchers/have_image_spec.rb