active_record_block_matchers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +4 -0
- data/active_record_block_matchers.gemspec +31 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/db/config.yml +11 -0
- data/db/migrate/20150225014908_create_people.rb +9 -0
- data/db/schema.rb +23 -0
- data/lib/active_record_block_matchers.rb +8 -0
- data/lib/active_record_block_matchers/config.rb +12 -0
- data/lib/active_record_block_matchers/create_a_matcher.rb +49 -0
- data/lib/active_record_block_matchers/version.rb +3 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 699fefdd842a22464b8b9b2a1c0e993915105a37
|
4
|
+
data.tar.gz: d49c20719ea62e4a90b993d0c164c720bf788c40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9809a07a608e39c2a693316fb53433f70424940b3a81d287209b63a0bfe10cc1e74ba737bcf0c9792b9f36c0e5cf7d93ed0eb90e0d7076b905cf17c30a087e5c
|
7
|
+
data.tar.gz: 584e1aef5720c1ea61066ade5bcc0d0e43b85f6624b7cfa467614cd7e3211e9f45c3dd8655c6d99bc498a5535a01d8229728f9fddc8c2fda29ca96834334ef62
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Nathan Wallace
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# ActiveRecordBlockMatchers
|
2
|
+
|
3
|
+
Custom RSpec matchers for ActiveRecord record creation
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'active_record_block_matchers'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install active_record_block_matchers
|
20
|
+
|
21
|
+
## Custom Matchers
|
22
|
+
|
23
|
+
#### `create_a_new`
|
24
|
+
|
25
|
+
Example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
expect { User.create!(username: "BOB") }
|
29
|
+
.to create_a_new(User)
|
30
|
+
.with_attributes(username: "bob")
|
31
|
+
```
|
32
|
+
|
33
|
+
This matcher relies on a `created_at` column existing on the given model class. The name of this column can be configured via `ActiveRecordBlockMatchers::Config.created_at_column_name = "your_column_name"`
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/[my-github-username]/active_record_block_matchers/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "active_record_block_matchers/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_record_block_matchers"
|
8
|
+
spec.version = ActiveRecordBlockMatchers::VERSION
|
9
|
+
spec.authors = ["Nathan Wallace"]
|
10
|
+
spec.email = ["nathan.m.wallace@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Additional RSpec custom matchers for ActiveRecord}
|
13
|
+
spec.description = %q{This gem adds custom block expectation matchers for RSpec, such as `expect { ... }.to create_a_new(User)`}
|
14
|
+
spec.homepage = "https://github.com/nwallace/active_record_block_matchers"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.required_ruby_version = ">= 1.9.3"
|
22
|
+
|
23
|
+
spec.add_dependency "activerecord", ">= 3.2.0"
|
24
|
+
spec.add_dependency "rspec", ">= 3.0.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "pry", "~> 0.10.1"
|
29
|
+
spec.add_development_dependency "sqlite3", "~> 1.3.10"
|
30
|
+
spec.add_development_dependency "standalone_migrations", "~> 2.1.5"
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "active_record_block_matchers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
data/db/config.yml
ADDED
data/db/schema.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20150225014908) do
|
15
|
+
|
16
|
+
create_table "people", :force => true do |t|
|
17
|
+
t.string "first_name"
|
18
|
+
t.string "last_name"
|
19
|
+
t.datetime "created_at", :null => false
|
20
|
+
t.datetime "updated_at", :null => false
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RSpec::Matchers.define :create_a_new do |klass|
|
2
|
+
supports_block_expectations
|
3
|
+
|
4
|
+
chain(:with_attributes) do |attributes|
|
5
|
+
@attributes = attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
match do |block|
|
9
|
+
@attributes ||= {}
|
10
|
+
time_before = Time.current
|
11
|
+
block.call
|
12
|
+
@created_records = klass.where("? > ?", ActiveRecordBlockMatchers::Config.created_at_column_name, time_before)
|
13
|
+
return false unless @created_records.count == 1
|
14
|
+
|
15
|
+
@failures = []
|
16
|
+
record = @created_records.first
|
17
|
+
@attributes.each do |field, value|
|
18
|
+
unless record.public_send(field) == value
|
19
|
+
@failures << [field, value, record.public_send(field)]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@failures.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
description do
|
26
|
+
"create a #{klass}, optionally verifying attributes"
|
27
|
+
end
|
28
|
+
|
29
|
+
failure_message do
|
30
|
+
if @created_records.count != 1
|
31
|
+
"the block should have created 1 #{klass}, but created #{@created_records.count}"
|
32
|
+
else
|
33
|
+
@failures.map do |field, expected, actual|
|
34
|
+
"Expected #{field} to be: #{expected}, but was: #{actual}"
|
35
|
+
end.join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
failure_message_when_negated do
|
40
|
+
if @created_records.count == 1
|
41
|
+
"the block should not have created a #{klass}, but created #{@created_records.count}"
|
42
|
+
else
|
43
|
+
"the block created a #{klass} that matched all given attributes"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
RSpec::Matchers.alias_matcher :create_a, :create_a_new
|
49
|
+
RSpec::Matchers.alias_matcher :create_an, :create_a_new
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_block_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Wallace
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.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.1
|
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.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.10
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.10
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: standalone_migrations
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.5
|
111
|
+
description: This gem adds custom block expectation matchers for RSpec, such as `expect
|
112
|
+
{ ... }.to create_a_new(User)`
|
113
|
+
email:
|
114
|
+
- nathan.m.wallace@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- active_record_block_matchers.gemspec
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- db/config.yml
|
130
|
+
- db/migrate/20150225014908_create_people.rb
|
131
|
+
- db/schema.rb
|
132
|
+
- lib/active_record_block_matchers.rb
|
133
|
+
- lib/active_record_block_matchers/config.rb
|
134
|
+
- lib/active_record_block_matchers/create_a_matcher.rb
|
135
|
+
- lib/active_record_block_matchers/version.rb
|
136
|
+
homepage: https://github.com/nwallace/active_record_block_matchers
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 1.9.3
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.5
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Additional RSpec custom matchers for ActiveRecord
|
160
|
+
test_files: []
|