Simple ad-hoc rspec matchers
When faced with an include "complicated string"
that has to be repeated in the spec, you could do something like this instead:
describe "Frobble page" do
let(:include_dribble) { include 'super-complicated-string-that-describes-dribble-in-the-page' }
it "includes dribble only if wibble is set" do
set_wibble
page.html.should include_dribble
unset_wibble
page.html.should_not include_dribble
end
end
While you could make a more complicated, global matcher, this kind of ad-hoc thing is easy to spot, local to the describe/context block and provides some stability if the string changes.
Written by Andrew Radev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#