rspec-controller-matchers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92b054074828fb3f2cad8abe30c60d1cdde7da4f
4
- data.tar.gz: 33a4408d9ff26ebeceb9abb2e926d2c1aa9ce03b
3
+ metadata.gz: 83137fbed1debf03048ac2d44ecce0fb61d32d99
4
+ data.tar.gz: 3878187d3139a17e044901faf842283afdb97a74
5
5
  SHA512:
6
- metadata.gz: 63453875c78e763f57ae44a20f2bf78a927eefe392632b57ff99d920e531613cce9e046fed43c9019c35a810f848ec15e97c3a82c68353ca965ac431f34949cb
7
- data.tar.gz: 74a99b4352fb4c95d5862e48c44c38ff804fd8d0b3396b3502486b2aa5510d8ceec9794b5411d52c92d381ebf6df299f3bb94f902ac04db8d7226ee045f9c21a
6
+ metadata.gz: 778a5995099cdfb4c0b21eec961221d7300871b74cc0eeb67cf315e362fbe7e2f1bf35bbe45b4f54e5fe878be60294ba9e1eb587454e0339905cbe713f8bf51a
7
+ data.tar.gz: c2a33f3d68312670982b9d6a60479b3117ac76246fcae2afa382e2d2b546056c012cb6263d891ba1769c9f2efa7a490f7a0f17103f0a200d5431bf30f57d9ad3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1 +1,4 @@
1
1
  require "rspec/matchers/render_local_matcher"
2
+ require "rspec/matchers/destroy_record_matcher"
3
+ require "rspec/matchers/create_record_matcher"
4
+ require "rspec/matchers/update_record_matcher"
@@ -0,0 +1,35 @@
1
+ RSpec::Matchers.define :create_record do |klass, attributes|
2
+ supports_block_expectations
3
+
4
+ match do |actual|
5
+ if using_form?
6
+ allow(form_klass).to receive(:new).and_call_original
7
+ expect_any_instance_of(form_klass).to receive(:save).and_call_original
8
+ end
9
+
10
+ expect {
11
+ actual.call
12
+ }.to change { klass.count }.by(1)
13
+
14
+ created_record_id = klass.maximum(klass.primary_key)
15
+ created_record = klass.find(created_record_id)
16
+ expect(created_record).to have_attributes(attributes)
17
+
18
+ if using_form?
19
+ expect(form_klass).to have_received(:new).with(kind_of(klass), kind_of(Hash))
20
+ end
21
+ end
22
+
23
+ def using_form(form_klass)
24
+ @form_klass = form_klass
25
+ self
26
+ end
27
+
28
+ def using_form?
29
+ form_klass.present?
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :form_klass, :form
35
+ end
@@ -0,0 +1,29 @@
1
+ RSpec::Matchers.define :destroy_record do |record|
2
+ supports_block_expectations
3
+
4
+ match do |actual|
5
+ if using_service?
6
+ allow(service_klass).to receive(:call).and_call_original
7
+ end
8
+
9
+ actual.call
10
+
11
+ expect(record.class.exists?(id: record.id)).to eq false
12
+ if using_service?
13
+ expect(service_klass).to have_received(:call)
14
+ end
15
+ end
16
+
17
+ def using_service(klass)
18
+ @service_klass = klass
19
+ self
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :service_klass
25
+
26
+ def using_service?
27
+ service_klass.present?
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ RSpec::Matchers.define :update_record do |resource, attributes|
2
+ supports_block_expectations
3
+
4
+ match do |actual|
5
+ if using_form?
6
+ allow(form_klass).to receive(:new).and_call_original
7
+ expect_any_instance_of(form_klass).to receive(:save).and_call_original
8
+ end
9
+
10
+ first_attribute_key = attributes.keys.first
11
+ initial_matcher = change { resource.reload.public_send(first_attribute_key) }.to(attributes[first_attribute_key])
12
+ update_all_attributes = attributes.except(first_attribute_key).inject(initial_matcher) do |current_matcher, (attribute_name, expected_value)|
13
+ current_matcher.and change { resource.public_send(attribute_name) }.to(expected_value)
14
+ end
15
+
16
+ expect { actual.call }.to update_all_attributes
17
+
18
+ if using_form?
19
+ expect(form_klass).to have_received(:new).with(have_attributes(id: resource.id), kind_of(Hash))
20
+ end
21
+ end
22
+
23
+ def using_form(form_klass)
24
+ @form_klass = form_klass
25
+ self
26
+ end
27
+
28
+ def using_form?
29
+ form_klass.present?
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :form_klass, :form
35
+ end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: rspec-controller-matchers 0.0.1 ruby lib
5
+ # stub: rspec-controller-matchers 0.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rspec-controller-matchers".freeze
9
- s.version = "0.0.1"
9
+ s.version = "0.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Stevo".freeze]
14
- s.date = "2017-05-08"
14
+ s.date = "2017-05-09"
15
15
  s.description = "Facilitate assertions for common controller responsibilites".freeze
16
16
  s.email = "blazejek@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -28,7 +28,10 @@ Gem::Specification.new do |s|
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "lib/rspec-controller-matchers.rb",
31
+ "lib/rspec/matchers/create_record_matcher.rb",
32
+ "lib/rspec/matchers/destroy_record_matcher.rb",
31
33
  "lib/rspec/matchers/render_local_matcher.rb",
34
+ "lib/rspec/matchers/update_record_matcher.rb",
32
35
  "rspec-controller-matchers.gemspec",
33
36
  "spec/fixtures/views/test/index.html.erb",
34
37
  "spec/fixtures/views/test/show.html.erb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-controller-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stevo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-08 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,7 +83,10 @@ files:
83
83
  - Rakefile
84
84
  - VERSION
85
85
  - lib/rspec-controller-matchers.rb
86
+ - lib/rspec/matchers/create_record_matcher.rb
87
+ - lib/rspec/matchers/destroy_record_matcher.rb
86
88
  - lib/rspec/matchers/render_local_matcher.rb
89
+ - lib/rspec/matchers/update_record_matcher.rb
87
90
  - rspec-controller-matchers.gemspec
88
91
  - spec/fixtures/views/test/index.html.erb
89
92
  - spec/fixtures/views/test/show.html.erb