On Thu, May 7, 2009 at 1:34 PM, Jarmo Pertman <[email protected]> wrote:
> Okay, I fiddled around a little and made this solution:
> module Spec
> module Example
> module Subject
> module ExampleMethods
>
> def should(matcher=nil)
> if matcher
> self == subject ?
> Spec::Expectations::PositiveExpectationHandler.handle_matcher(self,
> matcher) : subject.should(matcher)
> else
> self == subject ?
> Spec::Expectations::PositiveExpectationHandler.handle_matcher(self) :
> subject.should
> end
> end
>
> def should_not(matcher=nil)
> if matcher
> self == subject ?
> Spec::Expectations::NegativeExpectationHandler.handle_matcher(self,
> matcher) : subject.should_not(matcher)
> else
> self == subject ?
> Spec::Expectations::NegativeExpectationHandler.handle_matcher(self) :
> subject.should_not
> end
> end
> end
> end
> end
> end
>
> In short, if subject is set as self then I'm calling Kernel::should
> method's body directly. I don't know if there's any side effects that
> I'm omitting block parameter (although original should and should_not
> also doesn't send any blocks).
>
> Any problems that might arise with this patch?
The first problem is the dependency on subject, which is a construct
from rspec's example groups. This would make rspec's matchers unusable
outside rspec.
I'm also not clear on what your goal is, per my earlier response.
Please help me understand.
>
> Also, if my original example wasn't real life example enough, then I
> will give another one:
> require 'watir'
>
> describe "Google" do
> subject {self}
>
> before :all do
> @b = Watir::Browser.new
> @b.goto "http://www.google.com"
> end
>
> it "has google written on page" do
> should have_text("Google")
> end
>
> def has_text? text
> �[email protected]?(text)
> end
>
> end
>
> PS! I changed my poster nick, but I'm still the same "juuser" who made
> original thread.
>
> Regards,
> Jarmo
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users