[rspec-devel] matcher dsl
zach.dennis at gmail.com
Mon Mar 30 10:19:49 EDT 2009
On Sun, Mar 29, 2009 at 1:16 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> Hey all,
> rspec-1.2.0 introduced a new matcher DSL, which lets you define a
> matcher like this:
> Spec::Matchers.create :be_a_multiple_of do |expected|
> match do |actual|
> actual % expected == 0
> This defines a matcher that you can use in an example like this:
> 25.should be_a_multiple_of(5)
> It occurs to me that "Spec::Matchers.create" is not the most intuitive
> entry point. We're not defining Matchers (plural), nor are we really
> creating anything at the point of declaration.
> So I'm thinking of changing it (still supporting the original for now)
> to "Spec.matcher" or "Spec.define_matcher", or something similar.
> Anybody have any suggestions? My only restriction for the moment is
> that it should not be top level (i.e. define_matcher with no scoping).
I don't like the idea of top-level either. Personally I prefer
Spec::Matcher.define over Spec.define_matcher, but Spec.define_matcher
is better than Spec.matcher or Spec::Matchers.create.
It would be nice if you could do multiple matchers in one-swipe, only
having to rely on the namespace once. For example, I have a
matchers.rb file which houses the misc simple matchers for a project.
It'd be nice to say something like:
define :be_a_multiple_of do
define :be_something_else do
I don't know how other folks organize their simple matchers though,
> rspec-devel mailing list
> rspec-devel at rubyforge.org
More information about the rspec-devel