On Apr 18, 2011, at 7:49 AM, Jarmo Pertman wrote:
> On Apr 17, 6:58 pm, Justin Ko <jko...@gmail.com> wrote:
>> On Sun, Apr 17, 2011 at 10:01 AM, David Chelimsky
>> <dchelim...@gmail.com>wrote:
>>> On Apr 16, 2011, at 4:56 PM, Jarmo Pertman wrote:
>>
>>>> Hello!
>>
>>>> I've just added a new cool matcher #in into my framework WatirSplash
>>>> and thought that this could be integrated into RSpec directly actually
>>>> if there's any interest.
>>
>>>> WatirSplash uses Watir (or Watir-like) frameworks for testing web
>>>> pages via browser. If you're not familiar with it then here is a short
>>>> example how you had to test ajax-heavy application before:
>>
>>>> browser.link(:id => "someid").click
>>>> # let's wait up to 5 seconds for div to become visible
>>>> browser.wait_until(5) {browser.div(:id => "otherid").visible?}
>>
>>>> It was quite cumbersome and i thought about adding and #in matcher to
>>>> all matchers so i can do something like this instead:
>>>> # clicking the link changed div's text from "before" to "after" in a
>>>> maximum of 2 seconds
>>>> expect {
>>>> link.click
>>>> }.to change {div.text}.from("before").to("after").in(2)
>>
>>>> # clicking link makes div as present in a maximum of 2 seconds
>>>> link.click
>>>> div.should be_present.in(2)
>>
>>>> # clicking link makes div as visible in a maximum of 2 seconds
>>>> expect {
>>>> link.click
>>>> }.to make {div.visible?}.in(2)
>>
>>>> # use ActiveSupport for adding more meaning to numbers
>>>> require "active_support"
>>>> div.should exist.in(2.minutes)
>>
>>>> What do you guys think? Should i add that also into rspec-expectations
>>>> to make spec-ing easier where timing is involved? :)
>>
>>>> Jarmo Pertman
>>
>>> I _think_ I like the idea of a timing constraint, but #in seems too general
>>> to me. In fact, ActiveSupport is adding an #in? predicate [1] to Object that
>>> lets you specify that an object is in a collection:
>>
>>> 4.in?([2,3,4])
>>
>>> Also, I'm not sure if I'd want this to be a matcher extension or something
>>> built into rspec core. I'm open to ideas though. Anybody else?
>>
>>> [1]https://github.com/rails/rails/pull/258
>>
>> Definitely matcher extension.
> What does the "matcher extension" mean? E.g. some separate gem, which
> adds that method?
Not in this case. I meant something like this:
# new method in rspec-core
within(2).seconds do
obj.do_expensive_operation
end
vs this:
# new method in rspec-expectations
obj.should do_expensive_operation.within(2).seconds
>
> Didn't know that ActiveSupport adds #in? to Object,
Next release will have it - it's already in git.
> but it doesn't
> conflict with matcher's #in anyway.
It conflicts with the name :) It's a problem when we have one name that means
completely different things in different contexts.
Cheers,
David
ps - I moved your post to the bottom - please bottom or inline post, especially
on threads that are already moving in that direction.
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users