Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rm have_link()

  • Loading branch information...
commit 11791dea74697ee5eb503608f1acf057a80aa928 1 parent 288bd74
@pd authored
View
1  lib/rspec_hpricot_matchers.rb
@@ -2,7 +2,6 @@
require 'nokogiri'
require 'rspec_hpricot_matchers/have_tag'
-require 'rspec_hpricot_matchers/have_link'
class Nokogiri::XML::Element
alias body to_s
View
46 lib/rspec_hpricot_matchers/have_link.rb
@@ -1,46 +0,0 @@
-module RspecHpricotMatchers
- class HaveLink
- def initialize(example, url, options={})
- template = example.template
- @options = options
- link = Nokogiri.parse(template.link_to('ignore-me', url, options)).at('/')
- @expected_onclick = link[:onclick]
- @expected_href = link[:href]
- end
-
- def matches?(doc, &block)
- @doc = doc
- if @expected_onclick
- @doc.search("a[@href=#{@expected_href}]").any? do |link|
- link[:onclick] == @expected_onclick
- end
- else
- @doc.at("a[@href=#{@expected_href}]")
- end
- end
-
- def failure_message
- [
- "expected #{@doc.inner_html.inspect}",
- "to have a link with url",
- @expected_href.inspect,
- "and onclick",
- @expected_onclick.inspect
- ].join("\n")
- end
-
- def negative_failure_message
- [
- "expected #{@doc.inner_html.inspect}",
- "not to have a link with url",
- @expected_href.inspect,
- "and onclick",
- @expected_onclick.inspect
- ].join("\n")
- end
- end
-
- def have_link(url, options={})
- HaveLink.new(self, url, options)
- end
-end
View
81 spec/rspec_hpricot_matchers/have_link_spec.rb
@@ -1,81 +0,0 @@
-require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
-
-describe 'have_link' do
- attr_reader :fixture, :link, :html
- before(:each) do
- @fixture = Object.new
- fixture.extend RspecHpricotMatchers
- @html = "<div><a href='/foo/bar' onclick='deleteJsFunction();'>Some Text</a></div>"
- end
-
- def template
- @template ||= Object.new
- end
-
- describe "when the expected link does not have an onclick handler" do
- describe "when href match found" do
- it "passes" do
- template.should_receive(:link_to).with('ignore-me', '/foo/bar', {}).and_return(
- "<a href='/foo/bar'>ignore-me</a>"
- )
-
- hdoc = Hpricot(html)
- hdoc.should have_link('/foo/bar')
- end
- end
-
- describe "when href match not found" do
- it "fails" do
- template.should_receive(:link_to).with('ignore-me', '/foo/bar/baz', {}).and_return(
- "<a href='/foo/bar/baz'>ignore-me</a>"
- )
-
- hdoc = Hpricot(html)
- lambda {
- hdoc.should have_link('/foo/bar/baz')
- }.should raise_error(SpecFailed, /to have a link with url/)
- end
- end
- end
-
- describe "when the expected link has on onclick handler" do
- describe "when href match found" do
- describe "when onclick match found" do
- it "passes" do
- template.should_receive(:link_to).with('ignore-me', '/foo/bar', {:method => :delete}).and_return(
- "<a href='/foo/bar' onclick='deleteJsFunction();'>ignore-me</a>"
- )
-
- hdoc = Hpricot(html)
- hdoc.should have_link('/foo/bar', :method => :delete)
- end
- end
-
- describe "when onclick match not found" do
- it "fails" do
- template.should_receive(:link_to).with('ignore-me', '/foo/bar', {:method => :create}).and_return(
- "<a href='/foo/bar' onclick='createJsFunction();'>ignore-me</a>"
- )
-
- hdoc = Hpricot(html)
- lambda {
- hdoc.should have_link('/foo/bar', :method => :create)
- }.should raise_error(SpecFailed, /and onclick/)
- end
- end
- end
-
- describe "when href match not found" do
- it "fails" do
- template.should_receive(:link_to).with('ignore-me', '/foo/bar/baz', {:method => :delete}).and_return(
- "<a href='/foo/bar/baz' onclick='createJsFunction();'>ignore-me</a>"
- )
-
- hdoc = Hpricot(html)
- lambda {
- hdoc.should have_link('/foo/bar/baz', :method => :delete)
- }.should raise_error(SpecFailed, /to have a link with url/)
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.