yeastymobs-remarkable_mongomapper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Yeasty Mobs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Remarkable matchers for [MongoMapper](http://github.com/jnunemaker/mongomapper).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "remarkable_mongomapper"
8
+ gem.summary = %Q{MongoMapper Remarkable Matchers}
9
+ gem.email = "dev@yeastymobs.com"
10
+ gem.homepage = "http://github.com/yeastymobs/remarkable_mongomapper"
11
+ gem.authors = ["Nicolas Mérouze", "Vincent Hellot", "Mathieu Fosse"]
12
+
13
+ gem.add_dependency('remarkable', '~> 3.1.8')
14
+ gem.add_dependency('mongomapper', '~> 0.2.0')
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,6 @@
1
+ module Remarkable
2
+ module MongoMapper
3
+ class Base < Remarkable::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,43 @@
1
+ module Remarkable
2
+ module MongoMapper
3
+ module Matchers
4
+ class HaveKeyMatcher < Remarkable::MongoMapper::Base #:nodoc:
5
+
6
+ arguments :collection => :keys, :as => :key
7
+
8
+ optional :type
9
+
10
+ default_options :type => nil
11
+
12
+ collection_assertions :has_key?
13
+
14
+ before_assert do
15
+ @type = @options[:type]
16
+ end
17
+
18
+ protected
19
+
20
+ def has_key?
21
+ @subject.reader?(@key) && @subject.class.keys[@key] == ::MongoMapper::Key.new(@key, @type)
22
+ end
23
+
24
+ end
25
+
26
+ # Ensures that a key of the database actually exists.
27
+ #
28
+ # == Examples
29
+ #
30
+ # should_have_column :name, :type => String
31
+ #
32
+ # it { should have_column(:name, :type => String) }
33
+ # it { should have_column(:name, :phone_number, :type => String) }
34
+ # it { should have_column(:name).type(String) }
35
+ #
36
+ def have_key(*args, &block)
37
+ HaveKeyMatcher.new(*args, &block).spec(self)
38
+ end
39
+ alias :have_keys :have_key
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ module Remarkable
2
+ module MongoMapper
3
+ module Matchers
4
+ class ValidatePresenceOfMatcher < Remarkable::MongoMapper::Base #:nodoc:
5
+
6
+ arguments :collection => :keys, :as => :key
7
+
8
+ collection_assertions :allow_nil?
9
+
10
+ protected
11
+
12
+ def allow_nil?
13
+ @subject.send("#{@key}=", nil)
14
+ !@subject.valid? && !@subject.errors.on(@key).blank?
15
+ end
16
+
17
+ end
18
+
19
+ # Ensures that the model cannot be saved if one of the attributes listed is not present.
20
+ #
21
+ #
22
+ # == Examples
23
+ #
24
+ # should_validate_presence_of :name, :phone_number
25
+ # it { should validate_presence_of(:name, :phone_number) }
26
+ #
27
+ def validate_presence_of(*args, &block)
28
+ ValidatePresenceOfMatcher.new(*args, &block).spec(self)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ # Load Remarkable
2
+ unless Object.const_defined?('Remarkable')
3
+ begin
4
+ require 'remarkable'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ gem 'remarkable'
8
+ require 'remarkable'
9
+ end
10
+ end
11
+
12
+ # Add locale
13
+ dir = File.dirname(__FILE__)
14
+ Remarkable.add_locale File.join(dir, '..', 'locales', 'en.yml')
15
+
16
+ require File.join(dir, 'remarkable_mongomapper', 'base')
17
+
18
+ # Add matchers
19
+ Dir[File.join(dir, 'remarkable_mongomapper', 'matchers', '*.rb')].each do |file|
20
+ require file
21
+ end
22
+
23
+ # Include Remarkable MongoMapper matcher in appropriate ExampleGroup
24
+ if defined?(Spec::Rails)
25
+ Remarkable.include_matchers!(Remarkable::MongoMapper, Spec::Rails::Example::ModelExampleGroup)
26
+ else
27
+ Remarkable.include_matchers!(Remarkable::MongoMapper, Spec::Example::ExampleGroup)
28
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ en:
2
+ remarkable:
3
+ mongo_mapper:
4
+ have_key:
5
+ description: "have key(s) {{keys}}"
6
+ expectations:
7
+ has_key: "{{subject_name}} to have key named {{key}} with type {{type}}"
8
+
9
+ validate_presence_of:
10
+ description: "require {{keys}} to be set"
11
+ expectations:
12
+ allow_nil: "{{subject_name}} to require {{key}} to be set"
@@ -0,0 +1,60 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{remarkable_mongomapper}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nicolas M\303\251rouze", "Vincent Hellot", "Mathieu Fosse"]
9
+ s.date = %q{2009-07-28}
10
+ s.email = %q{dev@yeastymobs.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.md"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "LICENSE",
18
+ "README.md",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "lib/remarkable_mongomapper.rb",
22
+ "lib/remarkable_mongomapper/base.rb",
23
+ "lib/remarkable_mongomapper/matchers/have_key_matcher.rb",
24
+ "lib/remarkable_mongomapper/matchers/validate_presence_of_matcher.rb",
25
+ "locales/en.yml",
26
+ "remarkable_mongomapper.gemspec",
27
+ "spec/matchers/have_key_matcher_spec.rb",
28
+ "spec/matchers/validate_presence_of_matcher_spec.rb",
29
+ "spec/models.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/yeastymobs/remarkable_mongomapper}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{MongoMapper Remarkable Matchers}
38
+ s.test_files = [
39
+ "spec/matchers/have_key_matcher_spec.rb",
40
+ "spec/matchers/validate_presence_of_matcher_spec.rb",
41
+ "spec/models.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<remarkable>, ["~> 3.1.8"])
51
+ s.add_runtime_dependency(%q<mongomapper>, ["~> 0.2.0"])
52
+ else
53
+ s.add_dependency(%q<remarkable>, ["~> 3.1.8"])
54
+ s.add_dependency(%q<mongomapper>, ["~> 0.2.0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<remarkable>, ["~> 3.1.8"])
58
+ s.add_dependency(%q<mongomapper>, ["~> 0.2.0"])
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'have_key' do
4
+ subject do
5
+ Article.new
6
+ end
7
+
8
+ describe 'messages' do
9
+
10
+ it 'should contain a description' do
11
+ matcher = have_key(:title, :type => String)
12
+ matcher.description.should == 'have key(s) title'
13
+ end
14
+
15
+ it 'should set has_key? message' do
16
+ matcher = have_key(:owner, :type => String)
17
+ matcher.matches?(subject)
18
+ matcher.failure_message.should == 'Expected Article to have key named owner with type String'
19
+ end
20
+
21
+ end
22
+
23
+ describe 'matchers' do
24
+ it { should have_key(:title, :type => String) }
25
+ it { should have_keys(:title, :body, :type => String) }
26
+ end
27
+
28
+ describe 'macros' do
29
+ should_have_key :title, :type => String
30
+ should_have_keys :title, :body, :type => String
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe 'validate_presence_of' do
4
+ subject do
5
+ Article.new
6
+ end
7
+
8
+ describe 'messages' do
9
+
10
+ it 'should contain a description' do
11
+ matcher = validate_presence_of(:title, :body)
12
+ matcher.description.should == 'require title and body to be set'
13
+ end
14
+
15
+ it 'should set allow_nil? message' do
16
+ matcher = validate_presence_of(:body)
17
+ matcher.matches?(subject)
18
+ matcher.failure_message.should == 'Expected Article to require body to be set'
19
+ matcher.negative_failure_message.should == 'Did not expect Article to require body to be set'
20
+ end
21
+
22
+ end
23
+
24
+ describe 'matchers' do
25
+ it { should validate_presence_of(:title) }
26
+ it { should_not validate_presence_of(:body) }
27
+ end
28
+
29
+ describe 'macros' do
30
+ should_validate_presence_of(:title)
31
+ should_not_validate_presence_of(:body)
32
+ end
33
+ end
data/spec/models.rb ADDED
@@ -0,0 +1,6 @@
1
+ class Article
2
+ include MongoMapper::Document
3
+
4
+ key :title, String, :required => true
5
+ key :body, String
6
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+
3
+ gem "mongomapper", "~> 0.2.0"
4
+ require "mongomapper"
5
+
6
+ MongoMapper.database = "remarkable_mongomapper"
7
+
8
+ def reset_test_db!
9
+ MongoMapper.connection.drop_database("remarkable_mongomapper")
10
+ end
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.before(:all) { reset_test_db! }
14
+ config.after(:all) { reset_test_db! }
15
+ end
16
+
17
+ require File.join(File.dirname(__FILE__), "..", "lib", "remarkable_mongomapper")
18
+ require File.join(File.dirname(__FILE__), "models")
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yeastymobs-remarkable_mongomapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Nicolas M\xC3\xA9rouze"
8
+ - Vincent Hellot
9
+ - Mathieu Fosse
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-07-28 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: remarkable
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: 3.1.8
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongomapper
29
+ type: :runtime
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 0.2.0
36
+ version:
37
+ description:
38
+ email: dev@yeastymobs.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
46
+ files:
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/remarkable_mongomapper.rb
53
+ - lib/remarkable_mongomapper/base.rb
54
+ - lib/remarkable_mongomapper/matchers/have_key_matcher.rb
55
+ - lib/remarkable_mongomapper/matchers/validate_presence_of_matcher.rb
56
+ - locales/en.yml
57
+ - remarkable_mongomapper.gemspec
58
+ - spec/matchers/have_key_matcher_spec.rb
59
+ - spec/matchers/validate_presence_of_matcher_spec.rb
60
+ - spec/models.rb
61
+ - spec/spec.opts
62
+ - spec/spec_helper.rb
63
+ has_rdoc: false
64
+ homepage: http://github.com/yeastymobs/remarkable_mongomapper
65
+ licenses:
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: MongoMapper Remarkable Matchers
90
+ test_files:
91
+ - spec/matchers/have_key_matcher_spec.rb
92
+ - spec/matchers/validate_presence_of_matcher_spec.rb
93
+ - spec/models.rb
94
+ - spec/spec_helper.rb