From f51dd68c814332e598bb746c85c1c5003190e591 Mon Sep 17 00:00:00 2001 From: Sam Livingston-Gray Date: Fri, 30 Mar 2012 14:39:20 -0700 Subject: [PATCH] Add custom matcher method for RSpec --- lib/kookaburra/test_helpers.rb | 8 ++++++++ spec/kookaburra/test_helpers_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/kookaburra/test_helpers.rb b/lib/kookaburra/test_helpers.rb index 4ffcf0e..0b90d39 100644 --- a/lib/kookaburra/test_helpers.rb +++ b/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 @@ -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 diff --git a/spec/kookaburra/test_helpers_spec.rb b/spec/kookaburra/test_helpers_spec.rb index 1694545..d4d1239 100644 --- a/spec/kookaburra/test_helpers_spec.rb +++ b/spec/kookaburra/test_helpers_spec.rb @@ -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