require "spec_helper" describe ElabsMatchers::Matchers::HaveFormErrorsOn, :type => :feature do subject do Capybara.string("
" + html + "
") end shared_examples "a form error matcher" do it "returns true if the label and the error message is correct" do should have_form_errors_on("Name", "can't be blank") expect { should have_form_errors_on("Name", "must be royal") }.to fail_assertion expect { should have_form_errors_on("Message", "can't be blank") }.to fail_assertion end it "returns false if the label is correct by the error message is wrong" do should_not have_form_errors_on("Name", "Not good enough") expect { should_not have_form_errors_on("Name", "can't be blank") }.to fail_assertion end it "returns false if the label is wrong by the error message is correct" do should_not have_form_errors_on("Author", "can't be blank") end end describe "#have_form_errors_on" do context "with error as sibling to input" do it_behaves_like "a form error matcher" do let(:html) { %Q{ can't be blank } } end end context "with input nested in label" do it_behaves_like "a form error matcher" do let(:html) { %Q{ can't be blank} } end end end context "with error span outside input container" do it_behaves_like "a form error matcher" do let(:html) { %Q{
can't be blank
} } end end context "with twitter bootstrap markup normal inputs" do it_behaves_like "a form error matcher" do let(:html) { %Q{

can't be blank

} } end end context "with custom configured xpath selector" do before do ElabsMatchers.form_errors_on_selector = %Q{..//..//li[contains(@class,'error')]} end it_behaves_like "a form error matcher" do let(:html) { %Q{ } } end end end