active_record_block_matchers 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcffbe7450c275e8f73887b109de06322a94a8f4
4
- data.tar.gz: 5446e27ecf51297ba5a652776b957422118c6013
3
+ metadata.gz: 0d4300a69d179e6d1179829142e265a79dfca842
4
+ data.tar.gz: bd6f73e84dc9d9530d6f7771f478e413b68ba91f
5
5
  SHA512:
6
- metadata.gz: 091547dfd038261e271f38391d842261e955f5f44f0ac55631bc1ec4d330bcaa203387a97bc8cf257fdfba2a55066922875aacbbc9acc51fbec4d464fa6fa474
7
- data.tar.gz: d39f564c0f58925ae8bec51c5a0d6073a3fea5be6fc74a1c40456806a2443a4f4315ba02428e1793164e9b8284ada9562ba9adbe9a9df13cca42d2dc781c2c01
6
+ metadata.gz: 764d8f289679718c85409795111582ed667c7c6e0844cace7a402829f4dace7e63b7e94b12b70e0761e4bb80b99acae71ce6ae96e57348a3bf27b021c365064c
7
+ data.tar.gz: 700dbeb4e9890cb99da19301725c2fbd723edaa5e8aabf127e7157429dc5862314339e3543ad00f896656cfece516b3a838cfb55086d898239fde578dd9b780f
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
 
11
11
  *.sqlite3
12
+ .idea/
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.0
4
+ - 2.2.1
5
+ before_install:
6
+ - gem install bundler -v 1.8
7
+ script: rake travis
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ # Build Status
2
+ [![Build Status](https://travis-ci.org/nwallace/active_record_block_matchers.svg)](https://travis-ci.org/nwallace/active_record_block_matchers)
3
+
1
4
  # ActiveRecordBlockMatchers
2
5
 
3
6
  Custom RSpec matchers for ActiveRecord record creation
@@ -52,6 +55,14 @@ expect { User.create!(username: "BOB") }
52
55
  .with_attributes(username: "bob")
53
56
  ```
54
57
 
58
+ You can even use RSpec's [composable matchers][1]:
59
+
60
+ ```ruby
61
+ expect { User.create!(username: "bob") }
62
+ .to create_a_new(User)
63
+ .with_attributes(username: a_string_starting_with("b"))
64
+ ```
65
+
55
66
  If you need to make assertions about things other than attribute equality, you can also chain `.which` with a block, and your block will receive the newly created record:
56
67
 
57
68
  ```ruby
@@ -71,7 +82,7 @@ This matcher relies on a `created_at` column existing on the given model class.
71
82
 
72
83
  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.
73
84
 
74
- 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).
85
+ To install this gem onto your local machine, run `bundle exec rake install`.
75
86
 
76
87
  ## Contributing
77
88
 
@@ -80,3 +91,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
80
91
  3. Commit your changes (`git commit -am 'Add some feature'`)
81
92
  4. Push to the branch (`git push origin my-new-feature`)
82
93
  5. Create a new Pull Request
94
+
95
+
96
+ [1]: https://www.relishapp.com/rspec/rspec-expectations/v/3-3/docs/composing-matchers
data/Rakefile CHANGED
@@ -1,4 +1,16 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "standalone_migrations"
3
+ require 'rspec/core/rake_task'
3
4
 
4
5
  StandaloneMigrations::Tasks.load_tasks
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
9
+ t.rspec_opts = '--format documentation'
10
+ end
11
+
12
+ task :travis do
13
+ Rake::Task['db:setup'].invoke
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
data/bin/setup CHANGED
@@ -4,4 +4,4 @@ IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
6
 
7
- # Do any other automated setup that you need to do here
7
+ RAILS_ENV=test rake db:setup
@@ -27,7 +27,7 @@ RSpec::Matchers.define :create_a_new do |klass|
27
27
  @attribute_mismatches = []
28
28
 
29
29
  @attributes && @attributes.each do |field, value|
30
- unless record.public_send(field) == value
30
+ unless values_match?(value, record.public_send(field))
31
31
  @attribute_mismatches << [field, value, record.public_send(field)]
32
32
  end
33
33
  end
@@ -48,7 +48,8 @@ RSpec::Matchers.define :create_a_new do |klass|
48
48
  "the block should have created 1 #{klass}, but created #{@created_records.count}"
49
49
  elsif @attribute_mismatches.any?
50
50
  @attribute_mismatches.map do |field, expected, actual|
51
- "Expected #{field.inspect} to be #{expected.inspect}, but was #{actual.inspect}"
51
+ expected_description = is_composable_matcher?(expected) ? expected.description : expected.inspect
52
+ "Expected #{field.inspect} to be #{expected_description}, but was #{actual.inspect}"
52
53
  end.join("\n")
53
54
  else
54
55
  @which_failure.message
@@ -57,7 +58,7 @@ RSpec::Matchers.define :create_a_new do |klass|
57
58
 
58
59
  failure_message_when_negated do
59
60
  if @created_records.count == 1 && @attributes && @attribute_mismatches.none?
60
- "the block should not have created a #{klass} with attributes #{@attributes.inspect}, but did"
61
+ "the block should not have created a #{klass} with attributes #{format_attributes_hash(@attributes).inspect}, but did"
61
62
  elsif @created_records.count == 1 && @which_block && !@which_failure
62
63
  "the newly created #{klass} should have failed an expectation in the given block, but didn't"
63
64
  elsif @created_records.count == 1
@@ -66,6 +67,16 @@ RSpec::Matchers.define :create_a_new do |klass|
66
67
  "the block created a #{klass} that matched all given criteria"
67
68
  end
68
69
  end
70
+
71
+ def is_composable_matcher?(value)
72
+ value.respond_to?(:failure_message_when_negated)
73
+ end
74
+
75
+ def format_attributes_hash(attributes)
76
+ attributes.each_with_object({}) do |(field,value), memo|
77
+ memo[field] = is_composable_matcher?(value) ? value.description : value
78
+ end
79
+ end
69
80
  end
70
81
 
71
82
  RSpec::Matchers.alias_matcher :create_a, :create_a_new
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordBlockMatchers
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_block_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Wallace
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.4.5
170
+ rubygems_version: 2.4.3
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Additional RSpec custom matchers for ActiveRecord