Skip to content

Commit

Permalink
Type is mandatory.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerouze committed Jul 29, 2009
1 parent 8504512 commit 8c80da3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -5,8 +5,8 @@ Remarkable matchers for [MongoMapper](http://github.com/jnunemaker/mongomapper).
## Matchers ## Matchers


<pre><code> <pre><code>
it { should have_key(:name, :type => String) } it { should have_key(:name, String) }
it { should have_keys(:name, :phone_number, :type => String) } it { should have_keys(:name, :phone_number, String) }
it { should validate_presence_of(:name, :phone_number, :message => "not there!") } it { should validate_presence_of(:name, :phone_number, :message => "not there!") }
it { should belong_to(:user, :class_name => 'Person') } it { should belong_to(:user, :class_name => 'Person') }
it { should have_many(:users, :class_name => 'Person', :polymorphic => true) } it { should have_many(:users, :class_name => 'Person', :polymorphic => true) }
Expand Down
21 changes: 8 additions & 13 deletions lib/remarkable_mongomapper/matchers/have_key_matcher.rb
Expand Up @@ -3,17 +3,13 @@ module MongoMapper
module Matchers module Matchers
class HaveKeyMatcher < Remarkable::MongoMapper::Base class HaveKeyMatcher < Remarkable::MongoMapper::Base


arguments :collection => :attributes, :as => :attribute arguments :type, :collection => :attributes, :as => :attribute

optional :type

default_options :type => nil


collection_assertions :has_key? collection_assertions :has_key?


before_assert do # before_assert do
@type = @options[:type] # @type = @options[:type]
end # end


protected protected


Expand All @@ -27,14 +23,13 @@ def has_key?
# #
# == Examples # == Examples
# #
# should_have_key :name, :type => String # should_have_key :name, String
# #
# it { should have_key(:name, :type => String) } # it { should have_key(:name, String) }
# it { should have_keys(:name, :phone_number, :type => String) } # it { should have_keys(:name, :phone_number, String) }
# it { should have_key(:name).type(String) }
# #
def have_key(*args, &block) def have_key(*args, &block)
HaveKeyMatcher.new(*args, &block).spec(self) HaveKeyMatcher.new(args.pop, *args, &block).spec(self)
end end
alias :have_keys :have_key alias :have_keys :have_key


Expand Down
12 changes: 6 additions & 6 deletions spec/matchers/have_key_matcher_spec.rb
Expand Up @@ -8,25 +8,25 @@
describe 'messages' do describe 'messages' do


it 'should contain a description' do it 'should contain a description' do
matcher = have_key(:title, :type => String) matcher = have_key(:title, String)
matcher.description.should == 'have key(s) title' matcher.description.should == 'have key(s) title'
end end


it 'should set has_key? message' do it 'should set has_key? message' do
matcher = have_key(:owner, :type => String) matcher = have_key(:owner, String)
matcher.matches?(subject) matcher.matches?(subject)
matcher.failure_message.should == 'Expected Article to have key named owner with type String' matcher.failure_message.should == 'Expected Article to have key named owner with type String'
end end


end end


describe 'matchers' do describe 'matchers' do
it { should have_key(:title, :type => String) } it { should have_key(:title, String) }
it { should have_keys(:title, :body, :type => String) } it { should have_keys(:title, :body, String) }
end end


describe 'macros' do describe 'macros' do
should_have_key :title, :type => String should_have_key :title, String
should_have_keys :title, :body, :type => String should_have_keys :title, :body, String
end end
end end

0 comments on commit 8c80da3

Please sign in to comment.