diff --git a/Gemfile b/Gemfile index 67fd5c0d..3d9676a5 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ gem "rack-test" gem "mail" gem 'rails', '3.0.0.rc' gem 'sqlite3-ruby', :require=>'sqlite3' +gem 'nokogiri' #gem 'email_spec', :path => '.' gem 'capybara' gem 'database_cleaner' diff --git a/Rakefile b/Rakefile index 73fcf7bd..cc57292d 100644 --- a/Rakefile +++ b/Rakefile @@ -24,6 +24,7 @@ begin s.rubyforge_project = 'email-spec' s.add_runtime_dependency "mail", "~> 2.2" s.add_runtime_dependency "rspec", "~> 2.0" + s.add_runtime_dependency "nokogiri" end rescue LoadError puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" diff --git a/lib/email_spec/helpers.rb b/lib/email_spec/helpers.rb index 94686c07..2a87ee5b 100644 --- a/lib/email_spec/helpers.rb +++ b/lib/email_spec/helpers.rb @@ -1,4 +1,5 @@ require 'uri' +require 'nokogiri' require 'email_spec/deliveries' module EmailSpec @@ -69,7 +70,7 @@ def find_email(address, opts={}) end def links_in_email(email) - URI.extract(email.default_part_body.to_s, ['http', 'https']) + Nokogiri::HTML.parse(email.default_part_body.to_s).css('a').map { |link| link['href'] } end private diff --git a/spec/email_spec/helpers_spec.rb b/spec/email_spec/helpers_spec.rb index 2158922c..2c0f914c 100644 --- a/spec/email_spec/helpers_spec.rb +++ b/spec/email_spec/helpers_spec.rb @@ -19,6 +19,13 @@ end end + describe '#links_in_email' do + it "properly finds links surrounded by single quotes" do + email = Mail.new(:body => %{Click Here}) + links_in_email(email).should include %{http://www.example.com/test} + end + end + describe "#set_current_email" do it "should cope with a nil email" do lambda do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c1d65961..39f1ba7a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,4 +13,4 @@ def with_inspect_stub(str = "email") RSpec.configure do |config| config.mock_with :rspec -end \ No newline at end of file +end