[rspec-devel] [ rspec-Feature Requests-13837 ] alias :running, :lambda

noreply at rubyforge.org noreply at rubyforge.org
Tue Sep 11 21:40:17 EDT 2007


Feature Requests item #13837, was opened at 2007-09-11 09:46
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=13837&group_id=797

Category: expectation module
Group: None
Status: Closed
Priority: 3
Submitted By: sudara williams (sudara)
Assigned to: David Chelimsky (dchelimsky)
Summary: alias :running, :lambda

Initial Comment:
For everyday Rspec "reads like english" purposes, aliasing lambda as "running" would make for some fun spec writing:

running { something_risky }.should raise_error 
running { Fancy.operation }.should_not change(@simple, :factor)

or even

running { to_the_bathroom }.should_not change(person, :weight)


describe "A clear spec language" do
	it "should replace generic lowlevel language with intuitive goodies" do
  	running { 5.to_s }.call.should == lambda { 5.to_s }.call		
	end
end

----------------------------------------------------------------------

Comment By: Scott Taylor (smtlaissezfaire)
Date: 2007-09-12 01:40

Message:
I must say I agree with Aslak, because lambda screams in my face *delayed evaluation* 

The reason I suggested run was that a co-worker (who is new to rspec) suggested it.  He comes from Test::Unit and keeps on making this mistake:

my_method.should raise_error

If the code doesn't raise an error (say it returns nil) - then the error message will read something like the following:

NoMethodError: nil.call ...

(Obviously here the proc is trying to be called...) So maybe a better error message would work in this case?

(ps: What is the internal vs. external DSL conversation?)

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-09-11 22:19

Message:
Based on recent conversations re: internal vs external DSL's, I have to go w/ Aslak on this one. It's important that your customers understand the Strings you pass to describe and it. It's important that your fellow programmers understand the code in the block.

----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-09-11 22:10

Message:
-1

While I value readability, I value idioms more.

lambda is at ruby's core and it's a common idiom - I don't want an alias for it, but everyone is free to make their own alias.


----------------------------------------------------------------------

Comment By: Jay Levitt (jaylev)
Date: 2007-09-11 21:27

Message:
"run" doesn't read as English, though... 

running {this}.should do_that



----------------------------------------------------------------------

Comment By: Scott Taylor (smtlaissezfaire)
Date: 2007-09-11 21:26

Message:
How about run { do_something }.should raise_error ?

----------------------------------------------------------------------

Comment By: Jay Levitt (jaylev)
Date: 2007-09-11 09:55

Message:
+1!!

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=13837&group_id=797


More information about the rspec-devel mailing list