Created
January 4, 2009 16:09
-
-
Save mdarby/43089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec_helper.rb | |
module BoxMatcher | |
class Box | |
def initialize(name) | |
@name = name | |
end | |
def matches?(actual) | |
raise "You must supply a 'containing' attribute (.containing 'foo')" unless @contents | |
@actual = actual | |
# ___Here is where the real magic happens___ | |
# It is simply a regular expression that tests our | |
# expectations (the rendered HTML from the 'box' method) | |
# against what the response actually rendered | |
# If it matches, we have a passing spec. | |
@actual.body =~ /<div class="box"><span class="box_label">#{@name}:</span>.*#{@contents}.*n</div>/im | |
end | |
def containing(contents) | |
@contents = contents | |
self | |
end | |
def failure_message | |
"expected response to have a box describing '#{@name}', but it didn't" | |
end | |
def negative_failure_message | |
"expected response to not have a box describing '#{@name}', but it did" | |
end | |
end | |
def have_box_named(name) | |
Box.new(name) | |
end | |
end | |
... | |
Spec::Runner.configure do |config| | |
... | |
# Include our new Matcher module | |
config.include BoxMatcher, :type => :view | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment