[rspec-users] What's the new syntax for predicates?
David Chelimsky
dchelimsky at gmail.com
Wed Mar 14 18:48:16 EDT 2007
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
>
More information about the rspec-users
mailing list