[rspec-users] What's the new syntax for predicates?
s.ross
cwdinfo at gmail.com
Wed Mar 14 23:26:09 EDT 2007
One of the most compelling things about rSpec is the English-like way
it reads. I'd vote for anything that keeps it that way. If both can
"should" and "should be" can be supported it captures things like:
email.to.should include('me at mydomain.com')
and
my_ar_object.should be_valid
Just my $.02.
Steve
On Mar 14, 2007, at 3:48 PM, David Chelimsky wrote:
> On 3/14/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
>> On 3/14/07, Pat Maddox <pergesu at gmail.com> wrote:
>>> On 3/14/07, Pat Maddox <pergesu at gmail.com> wrote:
>>>> @settings.should allow_publish_ip("127.0.0.1") fails with
>>>> undefined method `allow_publish_ip' for #<#<Class:0x2f8fd48>:
>>>> 0x2f5a968>
>>>>
>>>> @settings.should_allow_publish_ip("127.0.0.1") works fine
>>>
>>> @settings.should_be allow_publish_ip("127.0.0.1") is it
>>
>> Unless I'm mistaken (David?) that's deprecated and will disappear. I
>> believe the way forward is:
>>
>> @settings.should be_allow_publish_ip("127.0.0.1")
>
> Sad, but true. You need to prefix w/ be_ because don't want to have
> method_missing doing any more magic than handling methods that start
> w/ be_ or have_.
>
> If you find this unpleasant, you can always provide your own helper
> methods. Here's a hack that you can use. Maybe we should add this to
> rspec?
>
> require 'rubygems'
> gem 'rspec'
> require 'spec'
>
> def predicate_matchers(*args)
> args.each do |arg|
> define_method(arg) do |*args|
> send "be_#{arg}", *args
> end
> end
> end
>
> class Thing
> def allow_publish_ip?(ip)
> true
> end
> end
>
> describe Thing do
> predicate_matchers :allow_publish_ip
> it "should allow publish ip 123" do
> Thing.new.should allow_publish_ip(123)
> end
> end
>
>>
>> Aslak
>>
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list