[rspec-devel] matcher dsl

Scott Taylor scott at railsnewbie.com
Sun Mar 29 15:02:03 EDT 2009

David Chelimsky 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
>         end
>       end

Spec::Matcher.define or Spec::Matcher.create is fine with me. 

It would only take "aliasing" the constant:

module Spec
  module Matchers
  Matcher = Matchers

> 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).
> Thanks,
> David
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the rspec-devel mailing list