rspice 0.6.3 → 0.6.4

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: 0541b0e229773383410a71203dfa8ee79487aa065cb53201389e2d33782cd1ad
4
- data.tar.gz: 5d83c5fd61474970247ba0e8fb2c0fa6e10b6b42eb61439e50e1f8d653e86166
3
+ metadata.gz: 65bc79afbd70cd3fed4389b2ed03f5bcd67e4a7e85fd54e858da133fc36aee7a
4
+ data.tar.gz: 2c43f5a8fdabbc0c7b70373edd5869bdcac6ea686051c070d45a963ad0145acc
5
5
  SHA512:
6
- metadata.gz: 24d40f36f7a8bd984fbbd95ff05d6cc9fe6a29a6ba75496024cd764234716ac04889d406bc90cf85c41267bde2e32491306c41c2ac3ce73335ed5861ea4f1aa5
7
- data.tar.gz: dc2154834145c3cb6fd7714fa6f34ca9a4935479fc6deebf98dbd48b1c0330febc2395682e3aed04521b712874fd75f60aed60a3a40545c2929d955802c15aa1
6
+ metadata.gz: a09f94cde9c825211b1c17ca2cc77cf85770ba98b7b46749408377ef8cf29ec047b0d596c3cd527868571cbc150b4a8ec463a2964be023934a0d32b45b8e4b49
7
+ data.tar.gz: 1229542d436fd7be6994c17f8d78f63737011a94d030544b036cf87f4f791d6dc026201fdfb0883ede36886b0318bf418160b94cdfad9a269beacdc8de05bcaa
data/README.md CHANGED
@@ -5,9 +5,14 @@
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/7e089c2617c530a85b17/maintainability)](https://codeclimate.com/github/Freshly/spicerack/maintainability)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/7e089c2617c530a85b17/test_coverage)](https://codeclimate.com/github/Freshly/spicerack/test_coverage)
7
7
 
8
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspice`. To experiment with that code, run `bin/console` for an interactive prompt.
9
-
10
- TODO: Delete this and the text above, and describe your gem
8
+ * [Installation](#installation)
9
+ * [Usage](#usage)
10
+ * [Custom Matchers](#custom-matchers)
11
+ * [Shared Context](#shared-context)
12
+ * [Shared Examples](#shared-examples)
13
+ * [Development](#development)
14
+ * [Contributing](#contributing)
15
+ * [License](#license)
11
16
 
12
17
  ## Installation
13
18
 
@@ -27,17 +32,44 @@ Or install it yourself as:
27
32
 
28
33
  ## Usage
29
34
 
30
- TODO: Write usage instructions here
35
+ To include the RSpice tools add the following to your `rails_helper.rb`:
36
+
37
+ ```ruby
38
+ require 'rspice'
39
+ ```
40
+
41
+ ## Custom Matchers
42
+
43
+ * [alias_method](lib/rspice/custom_matchers/alias_method.rb) tests usages of [Module#alias_method](https://apidock.com/ruby/Module/alias_method)
44
+ * [extend_module](lib/rspice/custom_matchers/extend_module.rb) tests usages of [Object#extend](https://www.apidock.com/ruby/Object/extend)
45
+ * [have_error_on_attribute](lib/rspice/custom_matchers/have_error_on_attribute.rb) tests usages of [ActiveModel::Errors](https://api.rubyonrails.org/classes/ActiveModel/Errors.html)
46
+ * [include_module](lib/rspice/custom_matchers/include_module.rb) tests usages of [Module#include](https://apidock.com/ruby/Module/include)
47
+ * [inherit_from](lib/rspice/custom_matchers/inherit_from.rb) tests inheritance of [Classes](https://apidock.com/ruby/Class)
48
+
49
+ ## Shared Context
50
+
51
+ * [with_an_example_descendant_class](lib/rspice/shared_context/with_an_example_descendant_class.rb) creates a named descendant of `described_class`
52
+ * [with_callbacks](lib/rspice/shared_context/with_callbacks.rb) defines callbacks for [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
53
+ * [with_example_class_having_callback](lib/rspice/shared_context/with_example_class_having_callback.rb) creates a class with
54
+
55
+ ## Shared Examples
56
+
57
+ * [a_class_pass_method](lib/rspice/shared_examples/a_class_pass_method.rb) tests class methods which take arguments that instantiate and call instance method of the same name
58
+ * [a_class_with_callback](lib/rspice/shared_examples/a_class_with_callback.rb) tests usage of [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
59
+ * [a_versioned_spicerack_gem](lib/rspice/shared_examples/a_versioned_spicerack_gem.rb) ensures gem compliance with internal standard of [Spicerack](https://github.com/Freshly/spicerack/)
60
+ * [an_example_class_with_callbacks](lib/rspice/shared_examples/an_example_class_with_callbacks.rb) tests for defined [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
61
+ * [an_inherited_property](lib/rspice/shared_examples/an_inherited_property.rb) tests usages of inherited [Class.class_attributes](https://apidock.com/rails/Class/class_attribute)
62
+ * [an_instrumented_event](lib/rspice/shared_examples/an_instrumented_event.rb) tests usage of [ActiveSupport::Notification](https://apidock.com/rails/ActiveSupport/Notifications)
31
63
 
32
64
  ## Development
33
65
 
34
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+ See Spicerack development instructions [here](https://github.com/Freshly/spicerack/blob/develop/README.md#development).
35
67
 
36
- 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+ To add a new example, context or matcher, add a new file to the appropriate directory in lib/rspice. Next, require the added file in its respective include file (such as `lib/rspice/custom_matchers.rb`).
37
69
 
38
70
  ## Contributing
39
71
 
40
- Bug reports and pull requests are welcome on GitHub at https://github.com/Freshly/spicerack.
72
+ See Spicerack contribution instructions [here](https://github.com/Freshly/spicerack/blob/develop/README.md#contributing).
41
73
 
42
74
  ## License
43
75
 
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher to spec inheritance.
3
+ # RSpec matcher that tests usages of [Module#alias_method](https://apidock.com/ruby/Module/alias_method)
4
4
  #
5
- # Usage:
5
+ # class Klass
6
+ # def old_name; end
7
+ # alias_method :alias_name, :old_name
8
+ # end
6
9
  #
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
10
+ # RSpec.describe Klass do
11
+ # it { is_expected.to alias_method :alias_name, :old_name }
12
+ # end
12
13
 
13
14
  RSpec::Matchers.define :alias_method do |alias_name, target_name|
14
15
  match do |instance|
@@ -1,31 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher for extend module.
3
+ # RSpec matcher that tests usages of [Object#extend](https://www.apidock.com/ruby/Object/extend)
4
4
  #
5
- # Usage:
5
+ # module Nodule; end
6
+ # class Klass
7
+ # extend Nodule
8
+ # end
6
9
  #
7
- # RSpec.describe User, type: :model do
8
- # subject { described_class }
9
- #
10
- # it { is_expected.to extend_module Authenticatable }
11
- # end
10
+ # RSpec.describe Klass do
11
+ # it { is_expected.to extend_module Nodule }
12
+ # end
12
13
 
13
14
  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
15
+ match { test_subject.singleton_class.included_modules.include? module_class }
16
+ description { "extended the module #{module_class}" }
17
+ failure_message { |described_class| "expected #{described_class} to extend module #{module_class}" }
18
+ failure_message_when_negated { |described_class| "expected #{described_class} not to extend module #{module_class}" }
29
19
 
30
20
  def test_subject
31
21
  subject.is_a?(Class) ? subject : subject.class
@@ -1,16 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher to test activities.
3
+ # RSpec matcher that tests usages of [ActiveModel::Errors](https://api.rubyonrails.org/classes/ActiveModel/Errors.html)
4
4
  #
5
- # Usage:
5
+ # class Klass < ApplicationRecord
6
+ # validate_uniqueness_of :attribute
7
+ # end
6
8
  #
7
- # RSpec.describe ApplicationRecord, type: :model do
8
- # subject { described_class.new }
9
+ # RSpec.describe Klass, type: :model do
10
+ # subject(:klass) { model.new(attribute: attribute) }
9
11
  #
10
- # before { # put record in invalid statae }
12
+ # let(:attribute) { "attribute" }
11
13
  #
12
- # it { is_expected.to have_error_on_attribute(:foo).with_detail_key(:bar) }
13
- # end
14
+ # before do
15
+ # model.create(attribute: attribute)
16
+ # klass.validate
17
+ # end
18
+ #
19
+ # it { is_expected.to have_error_on_attribute(:attribute).with_detail_key(:taken) }
20
+ # end
14
21
 
15
22
  RSpec::Matchers.define :have_error_on_attribute do |attribute|
16
23
  match do |record|
@@ -1,31 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher for include module.
3
+ # RSpec matcher that tests usages of [Module#include](https://apidock.com/ruby/Module/include)
4
4
  #
5
- # Usage:
5
+ # module Nodule; end
6
+ # class Klass
7
+ # include Nodule
8
+ # end
6
9
  #
7
- # RSpec.describe User, type: :model do
8
- # subject { described_class }
9
- #
10
- # it { is_expected.to include_module ApplicationRecord }
11
- # end
10
+ # RSpec.describe Klass do
11
+ # it { is_expected.to include_module Nodule }
12
+ # end
12
13
 
13
14
  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
15
+ match { test_subject.included_modules.include? module_class }
16
+ description { "included the module #{module_class}" }
17
+ failure_message { |described_class| "expected #{described_class} to include module #{module_class}" }
18
+ failure_message_when_negated { |described_class| "expected #{described_class} not to include module #{module_class}" }
29
19
 
30
20
  def test_subject
31
21
  subject.is_a?(Class) ? subject : subject.class
@@ -1,29 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher to spec inheritance.
3
+ # RSpec matcher that tests tests inheritance of [Classes](https://apidock.com/ruby/Class)
4
4
  #
5
- # Usage:
5
+ # class Klass < ApplicationRecord; end
6
6
  #
7
- # RSpec.describe User, type: :model do
8
- # subject { described_class }
9
- #
10
- # it { is_expected.to inherit_from ApplicationRecord }
11
- # end
7
+ # RSpec.describe Klass do
8
+ # it { is_expected.to inherit_from ApplicationRecord }
9
+ # end
12
10
 
13
11
  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
12
+ match { test_subject.ancestors.include? superclass }
13
+ description { "inherit from #{superclass}" }
14
+ failure_message { "expected #{described_class.name} to inherit from #{superclass}" }
15
+ failure_message_when_negated { "expected #{described_class.name} not to inherit from #{superclass}" }
25
16
 
26
- failure_message_when_negated do
27
- "expected #{described_class.name} not to inherit from #{superclass}"
17
+ def test_subject
18
+ subject.is_a?(Class) ? subject : subject.class
28
19
  end
29
20
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  require "rspice/custom_matchers/alias_method"
4
4
  require "rspice/custom_matchers/extend_module"
5
- require "rspice/custom_matchers/have_error_with_detail_key"
5
+ require "rspice/custom_matchers/have_error_on_attribute"
6
6
  require "rspice/custom_matchers/include_module"
7
7
  require "rspice/custom_matchers/inherit_from"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before { allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original }
5
+ end
@@ -1,5 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # RSpec context that creates a named descendant of `described_class`
4
+ #
5
+ # class Klass; end
6
+ #
7
+ # RSpec.describe Klass do
8
+ # include_context "with an example descendant class"
9
+ #
10
+ # let(:example_class_name) { "ChildClass" }
11
+ #
12
+ # it "has a descendant class" do
13
+ # expect(example_class.name).to eq example_class_name
14
+ # expect(ChildClass).to inherit_from described_class
15
+ # end
16
+ # end
17
+
3
18
  RSpec.shared_context "with an example descendant class" do
4
19
  let(:example_class) { Class.new(described_class) }
5
20
  let(:example_class_name) { Faker::Internet.domain_word.capitalize }
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec context that defines callbacks for [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
4
+ #
5
+ # class Klass
6
+ # include ActiveSupport::Callbacks
7
+ # define_callbacks :kallback
8
+ #
9
+ # def call
10
+ # run_callbacks(:kallback)
11
+ # end
12
+ # end
13
+ #
14
+ # RSpec.describe Klass do
15
+ # it_behaves_like "a class with callback" do
16
+ # include_context "with callbacks", :kallback
17
+ #
18
+ # subject(:callback_runner) { described_class.new.call }
19
+ #
20
+ # let(:example_class) { described_class }
21
+ # end
22
+ # end
23
+
24
+ RSpec.shared_context "with callbacks" do |callback|
25
+ before do
26
+ example_class.attr_accessor :before_hook_run, :around_hook_run, :after_hook_run
27
+ example_class.set_callback(callback, :before) { |obj| obj.before_hook_run = true }
28
+ example_class.set_callback(callback, :after) { |obj| obj.after_hook_run = true }
29
+ example_class.set_callback callback, :around do |obj, block|
30
+ obj.around_hook_run = true
31
+ block.call
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec context that creates a class with [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
4
+ #
5
+ # module Nodule
6
+ # def call
7
+ # run_callbacks(:kallback)
8
+ # end
9
+ # end
10
+ #
11
+ # RSpec.describe Nodule do
12
+ # describe "#initialize" do
13
+ # include_context "with example class having callback", :kallback
14
+ #
15
+ # subject(:callback_runner) { example_class.new.call }
16
+ #
17
+ # let(:example_class) { example_class_having_callback.include(Nodule) }
18
+ #
19
+ # it "runs the callbacks" do
20
+ # expect { callback_runner }.
21
+ # to change { example.before_hook_run }.from(nil).to(true).
22
+ # and change { example.around_hook_run }.from(nil).to(true).
23
+ # and change { example.after_hook_run }.from(nil).to(true)
24
+ # end
25
+ # end
26
+ # end
27
+
28
+ RSpec.shared_context "with example class having callback" do |callback|
29
+ let(:example_class_having_callback) do
30
+ Class.new do
31
+ include ActiveSupport::Callbacks
32
+ define_callbacks callback
33
+
34
+ class << self
35
+ attr_accessor :before_hook_run, :around_hook_run, :after_hook_run
36
+ end
37
+
38
+ set_callback(callback, :before) { |obj| obj.class.before_hook_run = true }
39
+ set_callback(callback, :after) { |obj| obj.class.after_hook_run = true }
40
+ set_callback callback, :around do |obj, block|
41
+ obj.class.around_hook_run = true
42
+ block.call
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rspice/shared_context/with_an_example_descendant_class"
4
+ require "rspice/shared_context/with_callbacks"
5
+ require "rspice/shared_context/with_example_class_having_callback"
@@ -1,5 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # RSpec example that tests class methods which take arguments that instantiate and call instance method of the same name
4
+ #
5
+ # class Klass
6
+ # # You can just call `Klass.do_something_extraordinary!(...)`! So convenient!!
7
+ # def self.do_something_extraordinary!(named_argument, *arguments, **options)
8
+ # new(named_argument, *arguments, **options).do_something_extraordinary!
9
+ # end
10
+ #
11
+ # attr_reader :some, :instance, :params
12
+ #
13
+ # def initialize(named_argument, *arguments, **options)
14
+ # @some = named_argument
15
+ # @instance = arguments
16
+ # @params = options
17
+ # end
18
+ #
19
+ # def do_something_extraordinary!
20
+ # # Important things happen here
21
+ # end
22
+ # end
23
+ #
24
+ # RSpec.describe Klass do
25
+ # describe ".do_something_extraordinary!" do
26
+ # it_behaves_like "a class pass method", :do_something_extraordinary!
27
+ # end
28
+ #
29
+ # describe "#do_something_extraordinary!" do
30
+ # it "does something important"
31
+ # end
32
+ # end
33
+
3
34
  RSpec.shared_examples_for "a class pass method" do |method|
4
35
  subject do
5
36
  if accepts_block?
@@ -39,8 +70,4 @@ RSpec.shared_examples_for "a class pass method" do |method|
39
70
  end
40
71
 
41
72
  it { is_expected.to eq output }
42
-
43
- it "has matching parameters with initialize" do
44
- expect(test_class.method(method).parameters).to eq test_class.instance_method(:initialize).parameters
45
- end
46
73
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec example that tests usage of [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
4
+ #
5
+ # module Nodule
6
+ # def call
7
+ # run_callbacks(:kallback)
8
+ # end
9
+ # end
10
+ #
11
+ # RSpec.describe Nodule do
12
+ # include_context "with example class having callback", :kallback
13
+ #
14
+ # subject(:instance) { example_class.new }
15
+ #
16
+ # let(:example_class) { example_class_having_callback.include(Nodule) }
17
+ #
18
+ # it_behaves_like "a class with callback" do
19
+ # subject(:callback_runner) { instance.call }
20
+ #
21
+ # let(:example) { example_class }
22
+ # end
23
+ # end
24
+
25
+ RSpec.shared_examples_for "a class with callback" do
26
+ it "runs the callbacks" do
27
+ expect { callback_runner }.
28
+ to change { example.before_hook_run }.from(nil).to(true).
29
+ and change { example.around_hook_run }.from(nil).to(true).
30
+ and change { example.after_hook_run }.from(nil).to(true)
31
+ end
32
+ end
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # RSpec example that ensures gem compliance with internal standard of [Spicerack](https://github.com/Freshly/spicerack/)
4
+ #
5
+ # RSpice.describe MyAwesomeGem do
6
+ # it_behaves_like "a versioned spicerack gem"
7
+ # end
8
+
3
9
  RSpec.shared_examples_for "a versioned spicerack gem" do
4
10
  it "has a version number" do
5
11
  expect(described_class::VERSION).to be_a String
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec example that tests for defined [ActiveSupport::Callbacks](https://apidock.com/rails/ActiveSupport/Callbacks)
4
+ #
5
+ # class Klass
6
+ # include ActiveSupport::Callbacks
7
+ # define_callbacks :kallback, :on_error
8
+ # end
9
+ #
10
+ # RSpec.describe Klass do
11
+ # it_behaves_like "an example class with callbacks", described_class, %i[kallback on_error]
12
+ # end
13
+
14
+ RSpec.shared_examples_for "an example class with callbacks" do |callback_module, callbacks|
15
+ subject(:example_class) { Class.new.include callback_module }
16
+
17
+ it { is_expected.to include_module ActiveSupport::Callbacks }
18
+
19
+ describe "__callbacks" do
20
+ subject { example_class.__callbacks.keys }
21
+
22
+ it { is_expected.to match_array Array.wrap(callbacks) }
23
+ end
24
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec example that tests usages of inherited [Class.class_attributes](https://apidock.com/rails/Class/class_attribute)
4
+ #
5
+ # class Klass
6
+ # class_attribute :_attributes, instance_writer: false, default: []
7
+ #
8
+ # class << self
9
+ # def inherited(base)
10
+ # base._attributes = _attributes.dup
11
+ # super
12
+ # end
13
+ #
14
+ # def define_attribute(attribute)
15
+ # _attributes << attribute
16
+ # end
17
+ # end
18
+ # end
19
+ #
20
+ # RSpec.describe Klass do
21
+ # describe ".inherited" do
22
+ # it_behaves_like "an inherited property", :define_attribute, :_attributes do
23
+ # let(:root_class) { example_class }
24
+ # end
25
+ # end
26
+ # end
27
+
28
+ # rubocop:disable Metrics/BlockLength
29
+ RSpec.shared_examples_for "an inherited property" do |property, attribute = "_#{property.to_s.pluralize}".to_sym|
30
+ let(:base_class) do
31
+ Class.new(root_class).tap { |klass| klass.__send__(property, :base) }
32
+ end
33
+
34
+ let(:parentA_class) do
35
+ Class.new(base_class).tap { |klass| klass.__send__(property, :parentA) }
36
+ end
37
+
38
+ let(:parentB_class) do
39
+ Class.new(base_class).tap { |klass| klass.__send__(property, :parentB) }
40
+ end
41
+
42
+ let!(:childA1_class) do
43
+ Class.new(parentA_class).tap { |klass| klass.__send__(property, :childA1) }
44
+ end
45
+
46
+ let!(:childA2_class) do
47
+ Class.new(parentA_class).tap { |klass| klass.__send__(property, :childA2) }
48
+ end
49
+
50
+ let!(:childB_class) do
51
+ Class.new(parentB_class).tap { |klass| klass.__send__(property, :childB) }
52
+ end
53
+
54
+ let(:expected_attribute_value) { expected_property_value }
55
+
56
+ shared_examples_for "an object with inherited property" do
57
+ it "has expected property" do
58
+ expect(example_class.public_send(attribute)).to match_array expected_attribute_value
59
+ end
60
+ end
61
+
62
+ describe "#base_class" do
63
+ subject(:example_class) { base_class }
64
+
65
+ let(:expected_property_value) { %i[base] }
66
+
67
+ include_examples "an object with inherited property"
68
+ end
69
+
70
+ describe "#parentA" do
71
+ subject(:example_class) { parentA_class }
72
+
73
+ let(:expected_property_value) { %i[base parentA] }
74
+
75
+ include_examples "an object with inherited property"
76
+ end
77
+
78
+ describe "#parentB" do
79
+ subject(:example_class) { parentB_class }
80
+
81
+ let(:expected_property_value) { %i[base parentB] }
82
+
83
+ include_examples "an object with inherited property"
84
+ end
85
+
86
+ describe "#childA1" do
87
+ subject(:example_class) { childA1_class }
88
+
89
+ let(:expected_property_value) { %i[base parentA childA1] }
90
+
91
+ include_examples "an object with inherited property"
92
+ end
93
+
94
+ describe "#childA2" do
95
+ subject(:example_class) { childA2_class }
96
+
97
+ let(:expected_property_value) { %i[base parentA childA2] }
98
+
99
+ include_examples "an object with inherited property"
100
+ end
101
+
102
+ describe "#childB" do
103
+ subject(:example_class) { childB_class }
104
+
105
+ let(:expected_property_value) { %i[base parentB childB] }
106
+
107
+ include_examples "an object with inherited property"
108
+ end
109
+ end
110
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec example that tests usage of [ActiveSupport::Notification](https://apidock.com/rails/ActiveSupport/Notifications)
4
+ #
5
+ # class Klass
6
+ # def initialize(user)
7
+ # @user = user
8
+ # end
9
+ #
10
+ # def call
11
+ # ActiveSupport::Notifications.instrument("a_thing_was_done.namespace", user: @user)
12
+ # end
13
+ # end
14
+ #
15
+ # RSpec.describe Klass do
16
+ # let(:instance) { test_class.new(user) }
17
+ # let(:user) { double }
18
+ #
19
+ # before { instance.call }
20
+ #
21
+ # it_behaves_like "an instrumented event", "a_thing_was_done.namespace" do
22
+ # let(:expected_data) do
23
+ # { user: user }
24
+ # end
25
+ # end
26
+ # end
27
+
28
+ RSpec.shared_examples_for "an instrumented event" do |event_name|
29
+ subject { ActiveSupport::Notifications }
30
+
31
+ let(:expected_event) { event_name }
32
+ let(:expected_args) { [ expected_event ].push(expected_data).compact }
33
+ let(:expected_data) do
34
+ {}
35
+ end
36
+
37
+ it { is_expected.to have_received(:instrument).with(*expected_args) }
38
+ end
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rspice/shared_examples/a_class_pass_method"
4
+ require "rspice/shared_examples/a_class_with_callback"
4
5
  require "rspice/shared_examples/a_versioned_spicerack_gem"
6
+ require "rspice/shared_examples/an_example_class_with_callbacks"
7
+ require "rspice/shared_examples/an_inherited_property"
8
+ require "rspice/shared_examples/an_instrumented_event"
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rspice
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.6.3"
5
+ VERSION = "0.6.4"
6
6
  end
data/lib/rspice.rb CHANGED
@@ -3,8 +3,11 @@
3
3
  require "rspec"
4
4
  require "faker"
5
5
 
6
+ require "active_support/core_ext/object/inclusion"
7
+
6
8
  require "rspice/version"
7
9
 
10
+ require "rspice/rspec_configuration"
8
11
  require "rspice/custom_matchers"
9
12
  require "rspice/shared_context"
10
13
  require "rspice/shared_examples"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-29 00:00:00.000000000 Z
11
+ date: 2019-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -51,14 +51,21 @@ files:
51
51
  - lib/rspice/custom_matchers.rb
52
52
  - lib/rspice/custom_matchers/alias_method.rb
53
53
  - lib/rspice/custom_matchers/extend_module.rb
54
- - lib/rspice/custom_matchers/have_error_with_detail_key.rb
54
+ - lib/rspice/custom_matchers/have_error_on_attribute.rb
55
55
  - lib/rspice/custom_matchers/include_module.rb
56
56
  - lib/rspice/custom_matchers/inherit_from.rb
57
+ - lib/rspice/rspec_configuration.rb
57
58
  - lib/rspice/shared_context.rb
58
59
  - lib/rspice/shared_context/with_an_example_descendant_class.rb
60
+ - lib/rspice/shared_context/with_callbacks.rb
61
+ - lib/rspice/shared_context/with_example_class_having_callback.rb
59
62
  - lib/rspice/shared_examples.rb
60
63
  - lib/rspice/shared_examples/a_class_pass_method.rb
64
+ - lib/rspice/shared_examples/a_class_with_callback.rb
61
65
  - lib/rspice/shared_examples/a_versioned_spicerack_gem.rb
66
+ - lib/rspice/shared_examples/an_example_class_with_callbacks.rb
67
+ - lib/rspice/shared_examples/an_inherited_property.rb
68
+ - lib/rspice/shared_examples/an_instrumented_event.rb
62
69
  - lib/rspice/version.rb
63
70
  homepage: https://www.freshly.com
64
71
  licenses: