Skip to content

Instantly share code, notes, and snippets.

@lenny
Created August 24, 2011 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenny/1169172 to your computer and use it in GitHub Desktop.
Save lenny/1169172 to your computer and use it in GitHub Desktop.
rspec macros
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 <joe@somewhere.com>', :should_be => 'joe@somewhere.com')
14 normalized('"Joe Blow" <joe@somewhere.com>', :should_be => 'joe@somewhere.com')
15
16 describe 'it strips whitespace' do
17 normalized(' joe@somewhere.com', :should_be => 'joe@somewhere.com')
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
Email
.normalize should strip email down to core address
normalizes 'Joe Blow <joe@somewhere.com>' as 'joe@somewhere.com'
normalizes '"Joe Blow" <joe@somewhere.com>' as 'joe@somewhere.com'
it strips whitespace
normalizes ' joe@somewhere.com' as 'joe@somewhere.com' (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 ' joe@somewhere.com' as 'joe@somewhere.com'
Failure/Error: Email.normalize(original).should == options[:should_be]
expected: "joe@somewhere.com"
got: " joe@somewhere.com" (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'
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 <joe@somewhere.com>') { should == 'joe@somewhere.com' }
15 normalized('"Joe Blow" <joe@somewhere.com>') { should == 'joe@somewhere.com' }
16
17 describe 'it strips whitespace' do
18 normalized(' joe@somewhere.com') { should == 'joe@somewhere.com' }
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
Email
.normalize should strip email down to core address
'Joe Blow <joe@somewhere.com>'
should == "joe@somewhere.com"
'"Joe Blow" <joe@somewhere.com>'
should == "joe@somewhere.com"
it strips whitespace
' joe@somewhere.com'
should == "joe@somewhere.com" (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 ' joe@somewhere.com'
Failure/Error: normalized(' joe@somewhere.com') { should == 'joe@somewhere.com' }
expected: "joe@somewhere.com"
got: " joe@somewhere.com" (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