rspice 0.2.0 → 0.2.5

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
  SHA256:
3
- metadata.gz: 4c5e223871fe2fa4953b4780ccf5580b0c138d236d049996c703c3f5b7c17e7b
4
- data.tar.gz: 7b0a7838b6c0615ef65807cb95272863456f62dc0b31c8aae23b22641ceafd29
3
+ metadata.gz: aa2eccc7a2ee562c1fccf79425a722e1dcbdd148c5e16e4c57cbf7d764b7b4f8
4
+ data.tar.gz: b0202df71dc3994f57f68898c51c99fb3c0ccd8f7a3098ece21d1014fc3b222f
5
5
  SHA512:
6
- metadata.gz: 2c11c725f520566ce3ce97b117c25180bd9628d034028f1ec4be08dbef07177c5e30b3b2648625225425b8d58e25cce286ed169ece4c3903bf39dfd6fe30d474
7
- data.tar.gz: 6dcaba676ce166e68112722597612aad775a6184fd76989a60ef68157894e3645a9274f5199fbdfbd99de9276e05bbe520c6e9aa0ac314c6807369b9e488236c
6
+ metadata.gz: 9e13f6c01268d681cdaabf6537b56924c77881521737ee3e74835f73b7f9d7462798fcfab9ba62752018b6311064bbc67ecc6d5c01a2bb7d24e677117de4727d
7
+ data.tar.gz: ae6894bc99e52ca53ad3f9094977b405c127c57a335d0e0d92b6c0f7e31b354e76822fddc087c551860632442a578c21473fdfded29d29a283a2ca0f24007467
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Rspice
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rspice.svg)](https://badge.fury.io/rb/rspice)
3
4
  [![Build Status](https://semaphoreci.com/api/v1/freshly/spicerack/branches/master/badge.svg)](https://semaphoreci.com/freshly/spicerack)
4
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/7e089c2617c530a85b17/maintainability)](https://codeclimate.com/github/Freshly/spicerack/maintainability)
5
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/7e089c2617c530a85b17/test_coverage)](https://codeclimate.com/github/Freshly/spicerack/test_coverage)
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rspec"
4
+ require "faker"
5
+
3
6
  require "rspice/version"
4
7
 
5
- module Rspice
6
- # Your code goes here...
7
- end
8
+ require "rspice/custom_matchers"
9
+ require "rspice/shared_context"
10
+ require "rspice/shared_examples"
11
+
12
+ module Rspice; end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspice/custom_matchers/alias_method"
4
+ require "rspice/custom_matchers/extend_module"
5
+ require "rspice/custom_matchers/include_module"
6
+ require "rspice/custom_matchers/inherit_from"
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher to spec inheritance.
4
+ #
5
+ # Usage:
6
+ #
7
+ # RSpec.describe User, type: :model do
8
+ # subject { described_class.new }
9
+ #
10
+ # it { is_expected.to alias_method :alias_name, :target_name }
11
+ # end
12
+
13
+ RSpec::Matchers.define :alias_method do |alias_name, target_name|
14
+ match do |instance|
15
+ instance.method(alias_name) == instance.method(target_name)
16
+ end
17
+
18
+ description do
19
+ "aliases #{target_name} as #{alias_name}"
20
+ end
21
+
22
+ failure_message do |instance|
23
+ "expected #{instance.class.name}##{alias_name} to be an alias of #{target_name}"
24
+ end
25
+
26
+ failure_message_when_negated do |instance|
27
+ "expected #{instance.class.name}##{alias_name} to not be an alias of #{target_name}"
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher for extend module.
4
+ #
5
+ # Usage:
6
+ #
7
+ # RSpec.describe User, type: :model do
8
+ # subject { described_class }
9
+ #
10
+ # it { is_expected.to extend_module Authenticatable }
11
+ # end
12
+
13
+ RSpec::Matchers.define :extend_module do |module_class|
14
+ match do
15
+ test_subject.singleton_class.included_modules.include? module_class
16
+ end
17
+
18
+ description do
19
+ "extended the module #{module_class}"
20
+ end
21
+
22
+ failure_message do |described_class|
23
+ "expected #{described_class} to extend module #{module_class}"
24
+ end
25
+
26
+ failure_message_when_negated do |described_class|
27
+ "expected #{described_class} not to extend module #{module_class}"
28
+ end
29
+
30
+ def test_subject
31
+ subject.is_a?(Class) ? subject : subject.class
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher for include module.
4
+ #
5
+ # Usage:
6
+ #
7
+ # RSpec.describe User, type: :model do
8
+ # subject { described_class }
9
+ #
10
+ # it { is_expected.to include_module ApplicationRecord }
11
+ # end
12
+
13
+ RSpec::Matchers.define :include_module do |module_class|
14
+ match do
15
+ test_subject.included_modules.include? module_class
16
+ end
17
+
18
+ description do
19
+ "included the module #{module_class}"
20
+ end
21
+
22
+ failure_message do |described_class|
23
+ "expected #{described_class} to include module #{module_class}"
24
+ end
25
+
26
+ failure_message_when_negated do |described_class|
27
+ "expected #{described_class} not to include module #{module_class}"
28
+ end
29
+
30
+ def test_subject
31
+ subject.is_a?(Class) ? subject : subject.class
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher to spec inheritance.
4
+ #
5
+ # Usage:
6
+ #
7
+ # RSpec.describe User, type: :model do
8
+ # subject { described_class }
9
+ #
10
+ # it { is_expected.to inherit_from ApplicationRecord }
11
+ # end
12
+
13
+ RSpec::Matchers.define :inherit_from do |superclass|
14
+ match do
15
+ described_class.ancestors.include? superclass
16
+ end
17
+
18
+ description do
19
+ "inherit from #{superclass}"
20
+ end
21
+
22
+ failure_message do
23
+ "expected #{described_class.name} to inherit from #{superclass}"
24
+ end
25
+
26
+ failure_message_when_negated do
27
+ "expected #{described_class.name} not to inherit from #{superclass}"
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspice/shared_context/with_an_example_descendant_class"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context "with an example descendant class" do
4
+ let(:example_class) { Class.new(described_class) }
5
+ let(:example_class_name) { Faker::Internet.domain_word.capitalize }
6
+
7
+ before { stub_const(example_class_name, example_class) }
8
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspice/shared_examples/a_class_pass_method"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: Jank - this should use Method#parameters, not Method#arity
4
+
5
+ RSpec.shared_examples_for "a class pass method" do |method|
6
+ subject do
7
+ if takes_options?
8
+ test_class.public_send(method, *arguments, **options)
9
+ else
10
+ test_class.public_send(method, *arguments)
11
+ end
12
+ end
13
+
14
+ let(:test_class) { described_class }
15
+ let(:initialize_arity) { test_class.instance_method(:initialize).arity }
16
+ let(:takes_options?) { (initialize_arity < 0) }
17
+ let(:argument_arity) { takes_options? ? (initialize_arity.abs - 1) : initialize_arity }
18
+
19
+ let(:arguments) do
20
+ Array.new(argument_arity) { double }
21
+ end
22
+ let(:options) { takes_options? ? Hash[*Faker::Lorem.words(2 * rand(1..2))].symbolize_keys : nil }
23
+ let(:instance) { instance_double(test_class) }
24
+ let(:output) { double }
25
+
26
+ before do
27
+ allow(instance).to receive(method).and_return(output)
28
+ if takes_options?
29
+ allow(test_class).to receive(:new).with(*arguments, **options).and_return(instance)
30
+ else
31
+ allow(test_class).to receive(:new).with(*arguments).and_return(instance)
32
+ end
33
+ end
34
+
35
+ it { is_expected.to eq output }
36
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rspice
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.5"
6
6
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.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.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
13
41
  description: A dash of spice to make your RSpec tests very nice.
14
42
  email:
15
43
  - garside@gmail.com
@@ -20,6 +48,15 @@ files:
20
48
  - LICENSE.txt
21
49
  - README.md
22
50
  - lib/rspice.rb
51
+ - lib/rspice/custom_matchers.rb
52
+ - lib/rspice/custom_matchers/alias_method.rb
53
+ - lib/rspice/custom_matchers/extend_module.rb
54
+ - lib/rspice/custom_matchers/include_module.rb
55
+ - lib/rspice/custom_matchers/inherit_from.rb
56
+ - lib/rspice/shared_context.rb
57
+ - lib/rspice/shared_context/with_an_example_descendant_class.rb
58
+ - lib/rspice/shared_examples.rb
59
+ - lib/rspice/shared_examples/a_class_pass_method.rb
23
60
  - lib/rspice/version.rb
24
61
  homepage: https://www.freshly.com
25
62
  licenses: