Skip to content

Commit

Permalink
be_true matcher from dsl to class
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Oct 20, 2011
1 parent 175873e commit 747c364
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/rspec/matchers/base_matcher.rb
Expand Up @@ -13,7 +13,7 @@ module BaseMatcher


attr_reader :actual, :expected attr_reader :actual, :expected


def initialize(expected) def initialize(expected=nil)
@expected = expected @expected = expected
end end


Expand All @@ -24,6 +24,10 @@ def failure_message_for_should
def failure_message_for_should_not def failure_message_for_should_not
"expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}" "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
end end

def description
split_words(name)
end
end end
end end
end end
11 changes: 8 additions & 3 deletions lib/rspec/matchers/be.rb
Expand Up @@ -2,14 +2,19 @@


module RSpec module RSpec
module Matchers module Matchers
class BeTrue
include BaseMatcher


# @method be_true def matches?(actual)
RSpec::Matchers.define :be_true do @actual = actual
match do |actual|
actual actual
end end
end end


def be_true
BeTrue.new
end

RSpec::Matchers.define :be_false do RSpec::Matchers.define :be_false do
match do |actual| match do |actual|
!actual !actual
Expand Down
14 changes: 13 additions & 1 deletion lib/rspec/matchers/pretty.rb
Expand Up @@ -6,6 +6,7 @@ def split_words(sym)
end end


def to_sentence(words) def to_sentence(words)
return "" unless words
words = words.map{|w| w.inspect} words = words.map{|w| w.inspect}
case words.length case words.length
when 0 when 0
Expand Down Expand Up @@ -42,8 +43,19 @@ def expected_to_sentence
end end


def name def name
defined?(@name) ? @name : self.class.name.split("::").last.downcase defined?(@name) ? @name : underscore(self.class.name.split("::").last)
end end

# Borrowed from ActiveSupport
def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
word.tr!("-", "_")
word.downcase!
word
end

end end
end end
end end

0 comments on commit 747c364

Please sign in to comment.