rspec-ohm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fed7e0b540b295b8ccaa6ff9fdd9d536238fa98
4
+ data.tar.gz: 63ba7873ca70230f49daa9ce9f4a1a278b970f6f
5
+ SHA512:
6
+ metadata.gz: fe583500503f482842a79948fe71104ddd983cbf24f4b046bf93d0822f86bec207e29ee01f0417c9bc2f44ff3388e824078a128fcd0e5cedb032385b601a42d6
7
+ data.tar.gz: 3eafe43cad0ac0669107d8888a65a065633265003fea768545637cbe3de4ba237cd014a4021b1c5c19ad2cfb57c22a683d6bd0f784d1aa305e726c945d101053
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.1
6
+ - 2.2
7
+ - rbx-2
8
+ services:
9
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-ohm.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 jc00ke
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Rspec::Ohm
2
+
3
+ RSpec matchers for [Ohm: Object Hash Mapper](http://ohm.keyvalue.org/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ group :development, :test do
11
+ gem 'rspec-ohm'
12
+ end
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rspec-ohm
22
+
23
+ ## Usage
24
+
25
+ Wire up:
26
+
27
+ ```ruby
28
+ RSpec.configure do |config|
29
+ config.include RSpec::Ohm, type: :model
30
+ end
31
+ ```
32
+
33
+ ## Matchers
34
+
35
+ ```ruby
36
+ class User < Ohm::Model
37
+
38
+ end
39
+
40
+ class Widget < Ohm::Model
41
+ attribute :name
42
+ index :name
43
+ unique :name
44
+
45
+ set :users, :User
46
+ end
47
+
48
+ RSpec.describe Widget do
49
+ it do
50
+ expect(subject).to have_attribute(:name)
51
+ expect(subject).to have_attribute(:name).with_index
52
+ end
53
+
54
+ it do
55
+ expect(subject).to have_set_of(:users).with_index
56
+ expect(subject).to have_set_of(:users).with_class(User)
57
+ end
58
+
59
+ it do
60
+ expect(subject).to have_unique(:name)
61
+ end
62
+ end
63
+ ```
64
+
65
+ ## TODO
66
+
67
+ 1. More matchers!
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( https://github.com/jc00ke/rspec-ohm/fork )
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
6
+ rescue LoadError
7
+ end
8
+
data/lib/rspec/ohm.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "ohm"
2
+
3
+ require "rspec"
4
+ require "rspec/core"
5
+ require "rspec/expectations"
6
+
7
+ module RSpec
8
+ module Ohm
9
+ extend RSpec::Matchers::DSL
10
+ end
11
+ end
12
+
13
+ require "rspec/ohm/version"
14
+ require "rspec/ohm/matchers/attributes"
15
+ require "rspec/ohm/matchers/set"
16
+ require "rspec/ohm/matchers/unique"
@@ -0,0 +1,22 @@
1
+ module RSpec
2
+ module Ohm
3
+ define :have_attribute do |expected|
4
+ match do |actual|
5
+ included = actual.class.attributes.include?(expected)
6
+ if defined?(@with_index) && @with_index
7
+ return included && actual.class.indices.include?(expected)
8
+ end
9
+ included
10
+ end
11
+
12
+ chain :with_index do
13
+ @with_index = true
14
+ end
15
+
16
+ failure_message do |actual|
17
+ index_msg = " with index" if @with_index
18
+ "expected #{actual.to_s} to have :#{expected} attribute#{index_msg}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module RSpec
2
+ module Ohm
3
+ define :have_set_of do |expected_set_name|
4
+ match do |actual|
5
+ actual.save
6
+ responds_to = actual.respond_to?(expected_set_name.to_sym)
7
+ with_class = if @klass
8
+ @actual_klass = actual.send(expected_set_name).model
9
+ @klass == @actual_klass
10
+ else
11
+ true
12
+ end
13
+ responds_to && with_class
14
+ end
15
+
16
+ chain :with_class do |klass|
17
+ @klass = klass
18
+ end
19
+
20
+ failure_message do |actual|
21
+ klass_msg = " of type #{@klass} but had type #{@actual_klass}" if @klass
22
+ "expected #{actual.class} to have a set of :#{expected}#{klass_msg}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module RSpec
3
+ module Ohm
4
+ define :have_unique do |expected|
5
+ match do |actual|
6
+ actual.class.uniques.include? expected
7
+ end
8
+
9
+ failure_message do |actual|
10
+ "expected #{actual.class} to track unique :#{expected}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module Ohm
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/rspec-ohm.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/ohm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-ohm"
8
+ spec.version = Rspec::Ohm::VERSION
9
+ spec.authors = ["jc00ke"]
10
+ spec.email = ["jesse@jc00ke.com"]
11
+ spec.summary = %q{RSpec matchers for Ohm}
12
+ spec.description = %q{RSpec matchers for Ohm}
13
+ spec.homepage = "https://github.com/jc00ke/rspec-ohm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "bundler", "~> 1.7"
22
+ spec.add_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "rspec", "~> 3.1"
24
+ spec.add_dependency "ohm", "~> 2.0"
25
+
26
+ spec.add_development_dependency "pry", "~> 0.10"
27
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "#have_attribute matcher" do
4
+ let(:model) {
5
+ Class.new(Ohm::Model) do
6
+ attribute :name
7
+ end.new
8
+ }
9
+
10
+ context "when the model has the attribute" do
11
+ it "matches" do
12
+ expect(model).to have_attribute(:name)
13
+ end
14
+ end
15
+
16
+ context "chained #with_index" do
17
+ context "with the index" do
18
+ let(:model) {
19
+ Class.new(Ohm::Model) do
20
+ attribute :name
21
+ index :name
22
+ end.new
23
+ }
24
+ it "matches" do
25
+ expect(model).to have_attribute(:name).with_index
26
+ end
27
+ end
28
+
29
+ context "without the index" do
30
+ it "includes expected attribute in failure message" do
31
+ expect {
32
+ expect(model).to have_attribute(:name).with_index
33
+ }.to raise_error { |e|
34
+ expect(e.message).to match(/index/)
35
+ }
36
+ end
37
+ end
38
+ end
39
+
40
+ context "when the model doesn't have the attribute" do
41
+ it "doesn't match" do
42
+ expect {
43
+ expect(model).to have_attribute(:asdf)
44
+ }
45
+ end
46
+
47
+ it "includes expected attribute in failure message" do
48
+ expect {
49
+ expect(model).to have_attribute(:asdf)
50
+ }.to raise_error { |e|
51
+ expect(e.message).to match(/asdf/)
52
+ }
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "#have_set_of matcher" do
4
+ class Bar < Ohm::Model; end
5
+ class Baz < Ohm::Model; end
6
+
7
+ class Foo < Ohm::Model
8
+ set :widgets, :Bar
9
+ end
10
+
11
+ class Qux < Ohm::Model
12
+ set :widgets, :Baz
13
+ end
14
+
15
+ let(:model) {
16
+ Foo.new
17
+ }
18
+
19
+ context "when the model has the set" do
20
+ it "matches" do
21
+ expect(model).to have_set_of(:widgets)
22
+ end
23
+ end
24
+
25
+ context "chained #with_class" do
26
+ context "with the class" do
27
+ it "matches" do
28
+ expect(model).to have_set_of(:widgets).with_class(Bar)
29
+ end
30
+ end
31
+
32
+ context "without the class" do
33
+
34
+ let(:model) {
35
+ Qux.new
36
+ }
37
+ it "includes the expected class in the failure message" do
38
+ expect {
39
+ expect(model).to have_set_of(:widgets).with_class(Bar)
40
+ }.to raise_error { |e|
41
+ expect(e.message).to match(/Bar/)
42
+ expect(e.message).to match(/Baz/)
43
+ }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "#have_unique matcher" do
4
+ class Foo < Ohm::Model
5
+ attribute :name
6
+ unique :name
7
+ end
8
+
9
+ let(:model) {
10
+ Foo.new
11
+ }
12
+
13
+ context "when the model has the uniqueness constraint" do
14
+ it "matches" do
15
+ expect(model).to have_unique(:name)
16
+ end
17
+ end
18
+
19
+ context "when the model doesn't have the uniqueness constraint" do
20
+ it "includes the attribute in the failure message" do
21
+ expect {
22
+ expect(model).to have_unique(:bar)
23
+ }.to raise_error { |e|
24
+ expect(e.message).to match(/bar/)
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,98 @@
1
+ require "ohm"
2
+
3
+ begin
4
+ Ohm.redis = if ENV.key?("TRAVIS")
5
+ Redic.new
6
+ else
7
+ Redic.new("redis://127.0.0.1:6380")
8
+ end
9
+ Ohm.redis.call("INFO")
10
+ rescue Errno::ECONNREFUSED
11
+ puts "We run redis on port 6380"
12
+ puts "so we don't overwrite any of your dev data"
13
+ puts "Please fire it up: `redis-server --port 6380`"
14
+ exit(1)
15
+ end
16
+
17
+ require "rspec/ohm"
18
+
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ RSpec.configure do |config|
21
+ config.include RSpec::Ohm
22
+
23
+ config.before(:each) do
24
+ Ohm.redis.call("FLUSHDB")
25
+ end
26
+
27
+ # rspec-expectations config goes here. You can use an alternate
28
+ # assertion/expectation library such as wrong or the stdlib/minitest
29
+ # assertions if you prefer.
30
+ config.expect_with :rspec do |expectations|
31
+ # This option will default to `true` in RSpec 4. It makes the `description`
32
+ # and `failure_message` of custom matchers include text for helper methods
33
+ # defined using `chain`, e.g.:
34
+ # be_bigger_than(2).and_smaller_than(4).description
35
+ # # => "be bigger than 2 and smaller than 4"
36
+ # ...rather than:
37
+ # # => "be bigger than 2"
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Prevents you from mocking or stubbing a method that does not exist on
45
+ # a real object. This is generally recommended, and will default to
46
+ # `true` in RSpec 4.
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
61
+ # For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-ohm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jc00ke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ohm
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: RSpec matchers for Ohm
84
+ email:
85
+ - jesse@jc00ke.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/rspec/ohm.rb
98
+ - lib/rspec/ohm/matchers/attributes.rb
99
+ - lib/rspec/ohm/matchers/set.rb
100
+ - lib/rspec/ohm/matchers/unique.rb
101
+ - lib/rspec/ohm/version.rb
102
+ - rspec-ohm.gemspec
103
+ - spec/rspec/ohm/matchers/have_attribute_spec.rb
104
+ - spec/rspec/ohm/matchers/have_set_of_spec.rb
105
+ - spec/rspec/ohm/matchers/have_unique_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/jc00ke/rspec-ohm
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: RSpec matchers for Ohm
131
+ test_files:
132
+ - spec/rspec/ohm/matchers/have_attribute_spec.rb
133
+ - spec/rspec/ohm/matchers/have_set_of_spec.rb
134
+ - spec/rspec/ohm/matchers/have_unique_spec.rb
135
+ - spec/spec_helper.rb