CARVIEW |
Every repository with this icon (

Every repository with this icon (

Description: | Collection of rspec matchers and cucumber steps for testing email in a rails app edit |
Homepage: | https://benmabey.com edit |
Public Clone URL: |
git://github.com/bmabey/email-spec.git
Give this clone URL to anyone.
git clone git://github.com/bmabey/email-spec.git
|
Your Clone URL: |
Use this clone URL yourself.
git clone git@github.com:bmabey/email-spec.git
|
Comments for bmabey's email-spec


And I should receive 1 email # features/step_definitions/email_steps.rb:51
expected: 1, got: 0 (using ==) Diff: @@ -1,2 +1,2 @@ -1 +0 (Spec::Expectations::ExpectationNotMetError) features/register.feature:15:in `And I should receive 1 email'
This thing fails no matter what I do. Any ideas?
Regards
Rajan

Awesome – I was just about to provide this fix. Now I don’t have to. Thanks

Actually, I’m wrong. It was intended to do both. My features use the way that was commented out.
For some reason github won’t let me fork atm, but here is what I propose.
def parse_email_for_link(email, text_or_regex) email.should have_body_text(text_or_regex) url = parse_email_for_explicit_link(email, text_or_regex) url ||= parse_email_for_anchor_text_link(email, text_or_regex) raise "No link found matching #{text_or_regex.inspect} in #{email}" unless url url end # e.g. confirm in https://confirm def parse_email_for_explicit_link(email, regex) regex = /#{Regexp.escape(regex)}/ unless regex.is_a?(Regexp) url = links_in_email(email).detect { |link| link =~ regex } URI::parse(url).request_uri if url end # e.g. Click here in <a href="https://confirm">Click here</a> def parse_email_for_anchor_text_link(email, link_text) email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>} URI.split($~[1])[5..-1].compact!.join("?").gsub("&", "&") # sub correct ampersand after rails switches it (https://dev.rubyonrails.org/ticket/4002) end

This is not how this method is intended to work.
The goal was for it to look in the link text, not in the url itself. links_in_email just returns the urls.

Ahh.. nm.. I see what you mean.. I’ll remove the dupe now. Thanks for pointing that out.

I’ve actually switched to using Jeweler.. so I’m not sure if this still applies. Mind taking a look at the current commit?

One of the files in here needs to be removed. Dupe of email_spec.gemspec

I would change that to amount.to_i Have had issues where it was giving me expected 1 got “1” and the like

Your Gem appears to be working now.
- => Successfully installed bmabey-email_spec-0.0.5

Yeah, having it in the README may confuse people. I’ll go ahead and remove it from there. That said, I think the actual step may be worth leaving in in case people want to clear it mid-scenario. I will often have steps in features that do nothing except commicate intent better.. people may want to use it in this fashion as well.
By putting ‘current_email_address’ into a module and then extending the world object we prevent polluting Object. While probably not a big issue, since this is just test code, something about having that method on ALL of my objects bugs me. By using Cucumber’s world hook the only object that will have the method is the World object that the steps are executed in.

I agree about the ‘And no emails have been sent’ being unnecessary in the readme. Maybe just remove it altogether? I think it will be rare that anyone needs to use that step. The situation would involve having to clear the e-mails within a scenario, which I’m not sure why anyone would want to do.
Also, why put current_email_address in a module?