Skip to content

Commit

Permalink
Improve description from such_that
Browse files Browse the repository at this point in the history
The "such that" prefix on the #such_that matcher didn't help in the
description when writing ad-hoc matchers. This removes that prefix,
which should allow for more natural descriptions.
  • Loading branch information
zaphod42 committed Jul 29, 2012
1 parent d1c9760 commit 2dcb2ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions lib/ramcrest/such_that.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ module Ramcrest
module SuchThat
module_function

def such_that(description = "<anonymous>", &matcher_block)
def such_that(description = "<anonymous such_that>", &matcher_block)
Matcher.new(description, matcher_block)
end

class Matcher
include Ramcrest::Matcher

attr_reader :description

def initialize(description, matcher_block)
singleton = class << self; self; end
singleton.send(:define_method, :matches?, matcher_block)
@description = description
end

def description
"such that #{@description}"
end
end
end
end
4 changes: 2 additions & 2 deletions test/such_that_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end

it "describes itself by default as an anonymous matcher" do
assert_that such_that { |value| }, a_matcher_described_as("such that <anonymous>")
assert_that such_that { |value| }, a_matcher_described_as("<anonymous such_that>")
end

it "allows for composing with other such_that matchers" do
Expand All @@ -27,6 +27,6 @@

it "can have a description provided" do
assert_that such_that("something is true") { |value| },
a_matcher_described_as("such that something is true")
a_matcher_described_as("something is true")
end
end

0 comments on commit 2dcb2ca

Please sign in to comment.