Skip to content

Commit

Permalink
Allow find_email to match text that contains regex sensitive characte…
Browse files Browse the repository at this point in the history
…rs. Closes #31
  • Loading branch information
curtis committed Jun 3, 2011
1 parent bcf8bae commit c02fb11
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 36 deletions.
7 changes: 2 additions & 5 deletions Gemfile
Expand Up @@ -5,8 +5,8 @@ gem "jeweler"
gem "cucumber"
gem "cucumber-rails"
gem "cucumber-sinatra"
gem "rspec", ">= 2.0.0.beta.19"
gem "rspec-rails", ">= 2.0.0.beta.19"
gem "rspec", ">= 2.0.1"
gem "rspec-rails", ">= 2.0.1"
gem "growl-glue", :require => "growl_glue"
gem "autotest"
gem "delayed_job", ">=2.0.3"
Expand All @@ -21,7 +21,4 @@ gem 'sqlite3-ruby', :require=>'sqlite3'
gem 'capybara'
gem 'database_cleaner'

gem 'rails', '3.0.0.rc'
gem 'sqlite3-ruby', :require => 'sqlite3'

gem "test-unit"
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -164,8 +164,8 @@ DEPENDENCIES
rack-test
rails (= 3.0.0.rc)
rake (>= 0.8.7)
rspec (>= 2.0.0.beta.19)
rspec-rails (>= 2.0.0.beta.19)
rspec (>= 2.0.1)
rspec-rails (>= 2.0.1)
sinatra
sqlite3-ruby
test-unit
2 changes: 1 addition & 1 deletion History.txt
Expand Up @@ -7,7 +7,7 @@

=== Bugfixes
* delivered_to matcher now compares both sender name and email address (Jason Garber)

* find_email now matches with_subject and with_text containing text with regex sensitive characters. Issue #31. (Curtis Miller)

== 1.1.1 2010-12-29
* Require "action_mailer" to avoid deprecation warnings. (Ryan Bigg)
Expand Down
13 changes: 7 additions & 6 deletions email_spec.gemspec
Expand Up @@ -8,8 +8,8 @@ Gem::Specification.new do |s|
s.version = "1.1.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ben Mabey", "Aaron Gibralter", "Mischa Fierer"]
s.date = %q{2011-05-30}
s.authors = [%q{Ben Mabey}, %q{Aaron Gibralter}, %q{Mischa Fierer}]
s.date = %q{2011-06-03}
s.description = %q{Easily test email in rspec and cucumber}
s.email = %q{ben@benmabey.com}
s.extra_rdoc_files = [
Expand Down Expand Up @@ -39,10 +39,10 @@ Gem::Specification.new do |s|
"rails_generators/email_spec/templates/email_steps.rb"
]
s.homepage = %q{http://github.com/bmabey/email-spec/}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rdoc_options = [%q{--charset=UTF-8}]
s.require_paths = [%q{lib}]
s.rubyforge_project = %q{email-spec}
s.rubygems_version = %q{1.3.7}
s.rubygems_version = %q{1.8.5}
s.summary = %q{Easily test email in rspec and cucumber}
s.test_files = [
"spec/email_spec",
Expand Down Expand Up @@ -113,6 +113,7 @@ Gem::Specification.new do |s|
"examples/rails3_root/features/errors.feature",
"examples/rails3_root/features/example.feature",
"examples/rails3_root/features/step_definitions",
"examples/rails3_root/features/step_definitions/email_steps.rb",
"examples/rails3_root/features/step_definitions/user_steps.rb",
"examples/rails3_root/features/step_definitions/web_steps.rb",
"examples/rails3_root/features/support",
Expand Down Expand Up @@ -158,6 +159,7 @@ Gem::Specification.new do |s|
"examples/sinatra_root/features/errors.feature",
"examples/sinatra_root/features/example.feature",
"examples/sinatra_root/features/step_definitions",
"examples/sinatra_root/features/step_definitions/email_steps.rb",
"examples/sinatra_root/features/step_definitions/user_steps.rb",
"examples/sinatra_root/features/step_definitions/web_steps.rb",
"examples/sinatra_root/features/support",
Expand All @@ -168,7 +170,6 @@ Gem::Specification.new do |s|
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
Expand Down
4 changes: 2 additions & 2 deletions examples/rails3_root/Gemfile
Expand Up @@ -11,7 +11,7 @@ group :test do
gem "cucumber-rails"
gem "database_cleaner"
gem 'capybara'
gem "rspec", ">= 2.0.0.beta.19"
gem "rspec-rails", ">= 2.0.0.beta.19"
gem "rspec", ">= 2.0.1"
gem "rspec-rails", ">= 2.0.1"
gem "email_spec", :path => "../../"
end
30 changes: 13 additions & 17 deletions examples/rails3_root/Gemfile.lock
Expand Up @@ -2,6 +2,7 @@ PATH
remote: ../../
specs:
email_spec (1.1.1)
mail (~> 2.2)
rspec (~> 2.0)

GEM
Expand Down Expand Up @@ -93,17 +94,16 @@ GEM
rake (>= 0.8.3)
thor (~> 0.14.0)
rake (0.8.7)
rspec (2.0.0.beta.19)
rspec-core (= 2.0.0.beta.19)
rspec-expectations (= 2.0.0.beta.19)
rspec-mocks (= 2.0.0.beta.19)
rspec-core (2.0.0.beta.19)
rspec-expectations (2.0.0.beta.19)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.19)
rspec-rails (2.0.0.beta.19)
rspec (= 2.0.0.beta.19)
webrat (>= 0.7.2.beta.1)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
rspec-rails (2.1.0)
rspec (~> 2.1.0)
rubyzip (0.9.4)
selenium-webdriver (0.0.27)
ffi (>= 0.6.1)
Expand All @@ -117,10 +117,6 @@ GEM
polyglot (>= 0.3.1)
trollop (1.16.2)
tzinfo (0.3.22)
webrat (0.7.2.beta.1)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)

PLATFORMS
ruby
Expand All @@ -133,7 +129,7 @@ DEPENDENCIES
email_spec!
mimetype-fu
rails (= 3.0.0.rc)
rspec (>= 2.0.0.beta.19)
rspec-rails (>= 2.0.0.beta.19)
rspec (>= 2.0.1)
rspec-rails (>= 2.0.1)
sqlite3-ruby
test-unit
4 changes: 2 additions & 2 deletions lib/email_spec/helpers.rb
Expand Up @@ -57,9 +57,9 @@ def read_emails_for(address)
def find_email(address, opts={})
address = convert_address(address)
if opts[:with_subject]
mailbox_for(address).find { |m| m.subject =~ Regexp.new(opts[:with_subject]) }
mailbox_for(address).find { |m| m.subject =~ Regexp.new(Regexp.escape(opts[:with_subject])) }
elsif opts[:with_text]
mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(opts[:with_text]) }
mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(Regexp.escape(opts[:with_text])) }
else
mailbox_for(address).first
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/email_spec/steps/templates/email_steps.rb
Expand Up @@ -57,7 +57,7 @@ def current_email_address
end

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
end

Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
Expand Down
64 changes: 64 additions & 0 deletions spec/email_spec/helpers_spec.rb
Expand Up @@ -133,4 +133,68 @@
it_should_behave_like 'something that sets the current email for recipients'
end
end

describe '#open_email' do
describe 'with subject' do
shared_examples_for 'something that opens the email with subject' do
before do
@to = "jimmy_bean@yahoo.com"
@email = Mail::Message.new(:to => @to, :subject => @subject)
stub!(:mailbox_for).with(@to).and_return([@email])
end

it "should open the email with subject" do
open_email(@to, :with_subject => @subject).should == @email
end
end

describe 'simple subject' do
before do
@subject = 'This is a simple subject'
end

it_should_behave_like 'something that opens the email with subject'
end

describe 'with regex sensitive characters' do
before do
@subject = '[app name] Contains regex characters?'
end

it_should_behave_like 'something that opens the email with subject'
end
end

describe 'with text' do
shared_examples_for 'something that opens the email with text' do
before do
@to = "jimmy_bean@yahoo.com"
@email = Mail::Message.new(:to => @to, :body => @body)
stub!(:mailbox_for).with(@to).and_return([@email])
end

it "should open the email with text" do
open_email(@to, :with_text => @text).should == @email
end
end

describe 'simple text' do
before do
@body = 'This is an email body that is very simple'
@text = 'email body'
end

it_should_behave_like 'something that opens the email with text'
end

describe 'with regex sensitive characters' do
before do
@body = 'This is an email body. It contains some [regex] characters?'
@text = '[regex] characters?'
end

it_should_behave_like 'something that opens the email with text'
end
end
end
end

2 comments on commit c02fb11

@netzpirat
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though it was a feature to find an email by regular expression - now I can't use it anymore.

@bmabey
Copy link
Collaborator

@bmabey bmabey commented on c02fb11 Jun 20, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right. The original poster of issue #31 was suggesting a patch that would allow for both types of behaviour. I didn't look at @curtis's patch closesly enough to realize that it was removing the ability to find emails by regular expressions. I've opened up issue #67 to deal with this. Thanks @netzpirat for pointing this out. For now locking to 1.1.1 is your best bet until this is resovled.

Please sign in to comment.