Created
August 24, 2011 20:45
-
-
Save lenny/1169172 to your computer and use it in GitHub Desktop.
rspec macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 require File.dirname(__FILE__) + "/spec_helper" | |
| 2 | |
| 3 require 'email' | |
| 4 | |
| 5 describe Email do | |
| 6 describe '.normalize', ' should strip email down to core address' do | |
| 7 def self.normalized(original, options) | |
| 8 it %{normalizes '#{original}' as '#{options[:should_be]}'} do | |
| 9 Email.normalize(original).should == options[:should_be] | |
| 10 end | |
| 11 end | |
| 12 | |
| 13 normalized('Joe Blow <[email protected]>', :should_be => '[email protected]') | |
| 14 normalized('"Joe Blow" <[email protected]>', :should_be => '[email protected]') | |
| 15 | |
| 16 describe 'it strips whitespace' do | |
| 17 normalized(' [email protected]', :should_be => '[email protected]') | |
| 18 end | |
| 19 | |
| 20 describe "it doesn't choke on invalid addresses" do | |
| 21 normalized('notanemail <ddsd>', :should_be => 'ddsd') | |
| 22 normalized('xyz', :should_be => 'xyz') | |
| 23 end | |
| 24 end | |
| 25 end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .normalize should strip email down to core address | |
| normalizes 'Joe Blow <[email protected]>' as '[email protected]' | |
| normalizes '"Joe Blow" <[email protected]>' as '[email protected]' | |
| it strips whitespace | |
| normalizes ' [email protected]' as '[email protected]' (FAILED - 1) | |
| it doesn't choke on invalid addresses | |
| normalizes 'notanemail <ddsd>' as 'ddsd' | |
| normalizes 'xyz' as 'xyz' | |
| Failures: | |
| 1) Email.normalize should strip email down to core address it strips whitespace normalizes ' [email protected]' as '[email protected]' | |
| Failure/Error: Email.normalize(original).should == options[:should_be] | |
| expected: "[email protected]" | |
| got: " [email protected]" (using ==) | |
| # org/jruby/RubyProc.java:268:in `call' | |
| # ./spec/lib/email_spec.rb:9:in `normalized' | |
| # org/jruby/RubyKernel.java:2028:in `instance_eval' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 require File.dirname(__FILE__) + "/spec_helper" | |
| 2 | |
| 3 require 'email' | |
| 4 | |
| 5 describe Email do | |
| 6 describe '.normalize', ' should strip email down to core address' do | |
| 7 def self.normalized(original, &blk) | |
| 8 describe "'#{original}'" do | |
| 9 subject { Email.normalize(original) } | |
| 10 it { instance_eval(&blk) } | |
| 11 end | |
| 12 end | |
| 13 | |
| 14 normalized('Joe Blow <[email protected]>') { should == '[email protected]' } | |
| 15 normalized('"Joe Blow" <[email protected]>') { should == '[email protected]' } | |
| 16 | |
| 17 describe 'it strips whitespace' do | |
| 18 normalized(' [email protected]') { should == '[email protected]' } | |
| 19 end | |
| 20 | |
| 21 describe "it doesn't choke on invalid addresses" do | |
| 22 normalized('notanemail <ddsd>') { should == 'ddsd' } | |
| 23 normalized('xyz') { should == 'xyz' } | |
| 24 end | |
| 25 end | |
| 26 end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .normalize should strip email down to core address | |
| 'Joe Blow <[email protected]>' | |
| should == "[email protected]" | |
| '"Joe Blow" <[email protected]>' | |
| should == "[email protected]" | |
| it strips whitespace | |
| ' [email protected]' | |
| should == "[email protected]" (FAILED - 1) | |
| it doesn't choke on invalid addresses | |
| 'notanemail <ddsd>' | |
| should == "ddsd" | |
| 'xyz' | |
| should == "xyz" | |
| Failures: | |
| 1) Email.normalize should strip email down to core address it strips whitespace ' [email protected]' | |
| Failure/Error: normalized(' [email protected]') { should == '[email protected]' } | |
| expected: "[email protected]" | |
| got: " [email protected]" (using ==) | |
| # org/jruby/RubyProc.java:268:in `call' | |
| # ./spec/lib/email_spec.rb:18:in `(root)' | |
| # org/jruby/RubyKernel.java:2028:in `instance_eval' | |
| # ./spec/lib/email_spec.rb:10:in `normalized' | |
| # org/jruby/RubyKernel.java:2028:in `instance_eval' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' | |
| # org/jruby/RubyArray.java:2336:in `collect' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment