Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Add custom matcher method for RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksam committed Mar 30, 2012
1 parent 2b82ed6 commit f51dd68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/kookaburra/test_helpers.rb
@@ -1,4 +1,5 @@
require 'kookaburra'
require 'kookaburra/mental_model_matcher'
require 'active_support/core_ext/module/delegation'

class Kookaburra
Expand Down Expand Up @@ -96,5 +97,12 @@ def k
# @method ui
# Delegates to {#k}
delegate :ui, :to => :k

# RSpec-style custom matcher that compares a given array with
# the current state of one named collection in the mental model
def match_mental_model_of(collection_key)
mental_model = Kookaburra.configuration.mental_model # naughty
MentalModel::Matcher.new(mental_model, collection_key)
end
end
end
21 changes: 21 additions & 0 deletions spec/kookaburra/test_helpers_spec.rb
Expand Up @@ -39,4 +39,25 @@
ui
end
end

describe "#match_mental_model_of" do
let(:mm) { Kookaburra.configuration.mental_model }

def sanity_check
match_mental_model_of(:widgets).should be_kind_of(Kookaburra::MentalModel::Matcher)
end

before(:each) do
sanity_check
mm.widgets[:foo] = 'FOO'
end

it "does a positive match" do
['FOO'].should match_mental_model_of(:widgets)
end

it "does a negative match" do
['BAR'].should_not match_mental_model_of(:widgets)
end
end
end

0 comments on commit f51dd68

Please sign in to comment.