Any interest in the following idea?
a.should include?("1:4") # if there's no matcher called include? then
just call include?
or something along those lines?
-r
on 2010-01-12 23:53
on 2010-01-14 16:37
On Jan 12, 2010, at 10:49 pm, rogerdpack wrote: > a.should include?("1:4") # if there's no matcher called include? then > just call include? Am I right thinking that this would mean writing a method_missing that creates a matcher for every unhandled message on the example object (whatever scope the #it block runs in)? If so, that could produce surprising behaviour if methods were silently turned into matchers and ignored. Maybe if you restricted it to ? methods it would not be so bad. But then, that's the point of the be_* handler. The only problem is that #include? is a verb not an adjective/noun. Can't say I've come across many of them, so it might be better in these cases to just write a method #a_container_for? ? Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran
on 2010-01-14 18:04
On Tue, Jan 12, 2010 at 5:49 PM, rogerdpack <rogerpack2005@gmail.com> wrote: > Any interest in the following idea? > > > a.should include?("1:4") # if there's no matcher called include? then > just call include? > > or something along those lines? -1 You can already say a.should include("1:4") which is clearer IMHO. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
on 2010-01-15 15:27
On 14 Jan 2010, at 17:02, Rick DeNatale wrote: > -1 > > You can already say > > a.should include("1:4") > > which is clearer IMHO. I assume Roger was referring to the general case though (which I still don't like) - and just happened to pick an example with an existing matcher. -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran
on 2010-01-18 10:39
On Jan 15, 2010, at 6:19 AM, Ashley Moran wrote: > > > I assume Roger was referring to the general case though (which I still don't like) - and just happened to pick an example with an existing matcher. If that's the case then I'd say it would be worth making a little macro to try it out. Something like define_simple_predicate_matcher :rise_from_the_ashes? It would need to define a simple matcher, allowing you to do Phoenix.new.should rise_from_the_ashes? which would naturally expand to Phoenix.new.rise_from_the_ashes?.should be_true Roger, if you're just talking about include?, follow Rick's suggestion. If you're talking about arbitrary predicates, then you can accomplish it in your own codebase with some simple metaprogramming, and see if it catches on with other folks. Pat
on 2010-01-18 16:06
On Jan 18, 2010, at 9:31 am, Pat Maddox wrote:
> define_simple_predicate_matcher :rise_from_the_ashes?
As an extension, how about:
define_simple_predicate_matcher :risen_from_the_ashes =>
:rise_from_the_ashes?
Also, in general, I think specs look better without ? symbols on
methods, my preference though
Ashley
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
on 2010-01-18 16:15
On Mon, Jan 18, 2010 at 9:03 AM, Ashley Moran <ashley.moran@patchspace.co.uk> wrote: > > On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: > >> define_simple_predicate_matcher :rise_from_the_ashes? > > As an extension, how about: > > define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? I'd rather not add a new DSL for the few cases in which we want to essentially delegate a predicate. We can already do this with the matcher DSL: Spec::Matchers.define :risen_from_the_ashes do match {|actual| actual.risen_from_the_ashes?} end This is better aligned w/ other matchers, more clear as to what it does, and isn't much more code. FWIW, David
on 2010-01-18 16:46
On Jan 18, 2010, at 3:12 pm, David Chelimsky wrote: > I'd rather not add a new DSL for the few cases in which we want to > essentially delegate a predicate. We can already do this with the > matcher DSL: I think Pat was just suggesting Roger try this in his own code. It's not something I especially want in RSpec, that was just a suggestion how Roger could play with the macro idea. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran
on 2010-01-18 21:43
On Jan 18, 2010, at 7:12 AM, David Chelimsky wrote: > > I'd rather not add a new DSL for the few cases in which we want to > essentially delegate a predicate. We can already do this with the > matcher DSL: > > Spec::Matchers.define :risen_from_the_ashes do > match {|actual| actual.risen_from_the_ashes?} > end > > This is better aligned w/ other matchers, more clear as to what it > does, and isn't much more code. This was a suggestion for OP to add to his own codebase, not RSpec, if he wanted to make the matcher definition even more concise. Pat
on 2010-01-18 21:48
On Mon, Jan 18, 2010 at 2:33 PM, Pat Maddox <mailinglists@patmaddox.com> wrote: >>> >> This is better aligned w/ other matchers, more clear as to what it >> does, and isn't much more code. > > This was a suggestion for OP to add to his own codebase, not RSpec, if he wanted to make the matcher definition even more concise. Understood. Thx.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.