rspec-sleeping_king_studios 2.3.0 → 2.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +40 -2
  3. data/DEVELOPMENT.md +48 -28
  4. data/README.md +55 -7
  5. data/lib/rspec/sleeping_king_studios.rb +7 -0
  6. data/lib/rspec/sleeping_king_studios/concerns/example_constants.rb +14 -3
  7. data/lib/rspec/sleeping_king_studios/concerns/focus_examples.rb +1 -1
  8. data/lib/rspec/sleeping_king_studios/configuration.rb +20 -17
  9. data/lib/rspec/sleeping_king_studios/examples/property_examples/class_properties.rb +32 -22
  10. data/lib/rspec/sleeping_king_studios/examples/property_examples/constants.rb +8 -0
  11. data/lib/rspec/sleeping_king_studios/examples/property_examples/predicates.rb +8 -4
  12. data/lib/rspec/sleeping_king_studios/examples/property_examples/private_properties.rb +29 -24
  13. data/lib/rspec/sleeping_king_studios/examples/property_examples/properties.rb +52 -27
  14. data/lib/rspec/sleeping_king_studios/matchers/core/have_changed.rb +16 -0
  15. data/lib/rspec/sleeping_king_studios/matchers/core/have_changed_matcher.rb +222 -0
  16. data/lib/rspec/sleeping_king_studios/matchers/core/have_constant.rb +2 -0
  17. data/lib/rspec/sleeping_king_studios/matchers/core/have_constant_matcher.rb +29 -27
  18. data/lib/rspec/sleeping_king_studios/matchers/core/have_predicate.rb +1 -0
  19. data/lib/rspec/sleeping_king_studios/matchers/core/have_predicate_matcher.rb +1 -1
  20. data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +1 -0
  21. data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +1 -0
  22. data/lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb +1 -0
  23. data/lib/rspec/sleeping_king_studios/support/value_spy.rb +67 -0
  24. data/lib/rspec/sleeping_king_studios/version.rb +3 -3
  25. metadata +24 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: db3edfd1090162224fb44315c4253e09c25dc877
4
- data.tar.gz: a2bef1ddd86161949fb43158c5418b4fd1c9842a
2
+ SHA256:
3
+ metadata.gz: 28e0a03888a052a73c2094ae42046f6f90467e1f01a85f2b8ac77ba2cdfddd18
4
+ data.tar.gz: ab77b0ad4c36165524e295910e38f16d7beea2a3bcac75c95589d8ab968a767e
5
5
  SHA512:
6
- metadata.gz: d107e3d8247775cd7467f086eeb7ac5cdd2f5ab7086ff38250e081f4c26c963f212a10162edbb8edcc8871e5b329dcd1f21f7993e7ef97ed87a4ce07c164489c
7
- data.tar.gz: dbc685520978c20ce0e9a72c996e1bbc60d97fe4b80a326cf682bebcbe2dbdbf8f895e233f638524aa03922cfd994c9187f7fdd1d619f83c7fb6d38b1c65a35b
6
+ metadata.gz: 83993d0ad852dd78792adf0bb00db3d763d50d137b484cf859d83cab359f3e5ceaf3bc0a18f6cfe9a50758cbf77ca22b36d6df61b7b971e70d5fdc969a6502f2
7
+ data.tar.gz: d1c5891ef2a2c7f38f1ffb12053f83126a65ee7e3fea6a1fe5ab9c2e39aad2acb803f33b2b059bb8d4df13ea406c54fe85a4701cedebb5a708f53b8dae2b665a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.4.0
4
+
5
+ Dropped support for RSpec 3.3.
6
+
7
+ Added RSpec::SleepingKingStudios.gem_path helper.
8
+
9
+ ### Concerns
10
+
11
+ Permit terse syntax for the example_class helper, e.g `example_class :MyClass, BaseClass` instead of `example_class :MyClass, base_class: BaseClass`.
12
+
13
+ Fixed a bug when using the example_class helper with a base_class that was another temporary class.
14
+
15
+ ### Examples
16
+
17
+ Improved failure messages for "has property" examples.
18
+
19
+ Aliased property matcher examples as 'should define \*', e.g. 'should have reader' is now aliased as 'should define reader'.
20
+
21
+ Fixed a bug when skipping shared examples with 'xinclude_examples' incorrectly generating a context of '(focused)' instead of '(skipped)'.
22
+
23
+ ### Matchers
24
+
25
+ Implemented the HaveChangedMatcher.
26
+
27
+ value = watch_value(object, :foo) # Create a value spy.
28
+
29
+ do_something
30
+
31
+ expect(value).to have_changed.from('initial value').to('final value')
32
+
33
+ Aliased HaveConstantMatcher#immutable as #frozen.
34
+
35
+ Aliased property matcher macros as define_*, e.g. have_reader is now aliased as define_reader.
36
+
37
+ ### Support
38
+
39
+ Implemented the ValueSpy for watching changes to an object method or a block.
40
+
3
41
  ## 2.3.0
4
42
 
5
- Added RSpec::SleepingKingStudios#version helper.
43
+ Added RSpec::SleepingKingStudios.version helper.
6
44
 
7
45
  Dropped support for RSpec 3.0 to 3.2.
8
46
 
@@ -60,7 +98,7 @@ Updated matcher testing examples (e.g. 'should pass with positive expectation',
60
98
 
61
99
  ### Matchers
62
100
 
63
- Internally refactored all matcher definitions to *\_matcher.rb, while the previous *.rb files define the macros which are added to example groups. The file names now accurately reflect what they define. In addition, the matchers can be required separately from the macros, e.g. to get around a naming conflict with another library. Also added support for aliasing matchers.
101
+ Internally refactored all matcher definitions to \*\_matcher.rb, while the previous \*.rb files define the macros which are added to example groups. The file names now accurately reflect what they define. In addition, the matchers can be required separately from the macros, e.g. to get around a naming conflict with another library. Also added support for aliasing matchers.
64
102
 
65
103
  #### `alias_method` Matcher
66
104
 
data/DEVELOPMENT.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Development Notes
2
2
 
3
- ## Version 2.3
3
+ ## Version 2.4
4
4
 
5
- ## Version 2.3.1
5
+ ### Bug Fixes
6
+
7
+ - when skipping a shared example group with xinclude_examples, the generated context is named '(focused)'. It should instead be named '(skipped)'.
6
8
 
7
- ### Features - Syntactic Sugar
9
+ ### Features
8
10
 
9
11
  - Alias `have_reader`, etc as `define_reader`.
10
12
  - Also alias shared examples.
@@ -12,30 +14,55 @@
12
14
  - Alias #immutable as #frozen.
13
15
  - Also alias shared examples.
14
16
 
15
- ## Future Tasks
17
+ ### Maintenance
18
+
19
+ - Refactor all macro specs from spec/rspec/sleeping_king_studios/matchers/macros to the directories corresponding to the source files.
20
+
21
+ ## Version 3.0
22
+
23
+ - Extract out Rails-specific matchers to RSpec::SleepingKingStudios::Rails.
24
+ - Refactor property, constant matchers to Define$1Matcher.
25
+ - HaveConstantMatcher, HaveReaderMatcher, HavePredicateMatcher, HavePropertyMatcher, HaveWriterMatcher.
26
+ - Designate define_* macros as primary, have_* as aliases.
27
+ - Designate 'should define \*' examples as primary.
28
+ - Add RuboCop CI step.
29
+ - Modernize code conventions.
30
+ - Add SimpleCov CI step.
16
31
 
17
- - Resolve Aruba deprecation warnings.
32
+ ## Future Tasks
18
33
 
19
34
  ### Bug Fixes
20
35
 
21
36
  - false negative on #alias_method?
22
37
  - need reproduction steps!
23
38
  - compare via Method#source_location equality and Method#original_name is expected?
39
+ - when using a shared example from another context, ensure that the rspec-sleeping_king_studios definitions are NOT excluded from the backtrace on a failure.
40
+ - can do this for now: |
24
41
 
25
- ### Features - Functionality
42
+ RSpec.configure do |config|
43
+ examples_path = File.join(RSpec::SleepingKingStudios.gem_path, 'lib', 'rspec', 'sleeping_king_studios', 'examples')
26
44
 
27
- - Add spy+matcher for expect(my_object, :my_method).to have_changed ?
45
+ config.project_source_dirs << examples_path
46
+ end
28
47
 
29
- ### Features - Quality of Life
48
+ ### Features - Core
30
49
 
31
- - Implement RespondToMatcher#with_optional_keywords, #with_required_keywords.
32
- - Implement be_immutable matcher.
33
- - Enhance RSpec matcher examples to display the #failure_message on a failed "should pass/fail with" example.
34
50
  - let?(:name) { } # Defines a memoized helper, but only if one is not already defined.
35
51
 
36
- ### Features - Syntactic Sugar
52
+ ### Features - Examples
53
+
54
+ - matcher examples:
55
+ - Enhance RSpec matcher examples to display the #failure_message on a failed "should pass/fail with" example.
56
+
57
+ ### Features - Matchers
37
58
 
38
- - Implement RespondToMatcher#with_at_least(N).arguments, equivalent to with(N).arguments.and_unlimited_arguments.
59
+ - BeImmutableMatcher (NEW):
60
+ - Implement be_immutable matcher.
61
+ - HaveChangedMatcher (NEW):
62
+ - Add spy+matcher for expect(my_object, :my_method).to have_changed ?
63
+ - RespondToMatcher:
64
+ - Implement RespondToMatcher#with_optional_keywords, #with_required_keywords.
65
+ - Implement RespondToMatcher#with_at_least(N).arguments, equivalent to with(N).arguments.and_unlimited_arguments.
39
66
 
40
67
  ### Maintenance
41
68
 
@@ -49,28 +76,16 @@
49
76
  - Use matcher class name instead of macro names?
50
77
  - Clarify documentation of parameters - YARD-like?
51
78
  - Integration specs for shared example groups
52
- - Run in external process, parse output for expected values (similar to Aruba)
79
+ - Run in external process, parse output for expected values (use Aruba?)
53
80
  - Allows testing of failing example groups
54
81
  - Pare down Cucumber features for matchers - repurpose as documentation/examples only.
55
82
  - Break down into smaller (bite-sized?) individual examples.
56
83
  - RuboCop - use RSpec rule file as starting point?
84
+ - frozen_string_literals pragma?
57
85
 
58
86
  ## Icebox
59
87
 
60
- - Chainable examples: |
61
-
62
- it 'should do something' do
63
- # Always run.
64
- end.
65
- then 'should do something else' do
66
- # Only runs if first example passes.
67
- end.
68
- then 'should do a third thing' do
69
- # Only runs if first and second examples pass.
70
- end
71
-
72
88
  - Implement Matchers::define_negated_matcher.
73
- - Implement RespondTo#with_optional_keywords.
74
89
  - Implement negated compound matchers, e.g. expect().to match().and_not other_match()
75
90
  - Alias as "but_not"?
76
91
  - Implement benchmarking specs:
@@ -85,9 +100,10 @@
85
100
  - Implement shared example group for Rails routing, 'should route to'
86
101
  - Add alt doc test formatter - --format=list ? --format=documentation-list ?
87
102
  - Prints full expanded example name for each example
103
+ - Allows basic diffing of "what tests were run?"
88
104
  - Add minimal test formatter - --format=smoke ? --format=librarian ? --format=quiet ?
89
105
  - Prints nothing for examples
90
- - Suppress STDOUT output? As configurable option for any formatted?
106
+ - Suppress STDOUT output? As configurable option for any formatter?
91
107
  - Add DSL for shared_examples-heavy specs?
92
108
  - #should(name) => include_examples "should #{name}"
93
109
  - #with(name) => wrap_context "with #{name}"
@@ -95,3 +111,7 @@
95
111
  - General project for using matchers as Ruby objects
96
112
  - Inspectable - expectations, comparison results exposed via readers
97
113
  - Favor readers over instance variables.
114
+ - Ordering options:
115
+ - group_by: option - allows grouping of examples, e.g. group_by: :fixtures. Groups all examples by each value of the given metadata. Also before/after/around(:group, fixtures: true)?
116
+ - example group-level ordering
117
+ - order :defined_and_fail_fast - run the specs in given order, but after a spec fails all further specs in that example group are marked as pending.
data/README.md CHANGED
@@ -4,13 +4,13 @@ A collection of matchers and extensions to ease TDD/BDD using RSpec. Extends bui
4
4
 
5
5
  ## Support
6
6
 
7
- RSpec::SleepingKingStudios is tested against RSpec 3.3 through 3.6.
7
+ RSpec::SleepingKingStudios is tested against RSpec 3.3 through 3.7.
8
8
 
9
9
  Currently, the following versions of Ruby are officially supported:
10
10
 
11
- * 2.2
12
11
  * 2.3
13
12
  * 2.4
13
+ * 2.5
14
14
 
15
15
  For Ruby 2.0 support, use version 2.1 or earlier: `gem "rspec-sleeping_king_studios", "~> 2.1.1"`.
16
16
 
@@ -517,6 +517,34 @@ Checks if the actual object forwards the specified method to the specified targe
517
517
  * **`#with_a_block:`** (also `and_a_block`) Specifies that when the method is called on the actual object a block argument, thhe block is then passed on to the target object when the method is called on the target.
518
518
  * **`#and_return`:** Expects one or more arguments. The method is called on the actual object one time for each value passed into `#and_return`. Specifies that the return value of calling the method on the actual object is the corresponding value passed into `#and_return`.
519
519
 
520
+ #### `#have_changed` Matcher
521
+
522
+ require 'rspec/sleeping_king_studios/matchers/core/have_changed'
523
+
524
+ Checks that a watched value has changed. The `have_changed` matcher must be paired with a value spy (see `#watch_value`, below), which is typically created with the `watch_value` helper. This is an alternative to the core RSpec `change` matcher, but allows you track changes to multiple values without nested expectations or other workarounds.
525
+
526
+ **How To Use**
527
+
528
+ spy = watch_value(object, property)
529
+
530
+ object.property = 'new value'
531
+
532
+ expect(spy).to have_changed
533
+
534
+ You can also create a value spy with a block:
535
+
536
+ spy = watch_value { object.property }
537
+
538
+ **Parameters:** None.
539
+
540
+ **Chaining:**
541
+
542
+ * **by:** Expects one argument. If the value has changed, then the current value will be subtracted from the initial value and the difference compared with the expected value given to `#by`. *Note:* `not_to have_changed.by()` is not supported and will raise an error.
543
+ * **from:** Expects one argument. The initial value of the spy (at the time the spy was initialized) must be equal to the given value.
544
+ * **to:** Expects one argument. The current value of the spy (at the time `expect().to have_changed` is evaluated) must be equal to the given value.
545
+
546
+ **Warning:** Make sure that the value spy is initialized before running whatever code is expected to change the value. In particular, if you are setting up your spies using RSpec `let()` statements, it is recommended to use the imperative `let!()` form to ensure that the spies are initialized before running the example.
547
+
520
548
  #### `#have_constant` Matcher
521
549
 
522
550
  require 'rspec/sleeping_king_studios/matchers/core/have_constant'
@@ -525,11 +553,11 @@ Checks for the presence of a defined constant `:CONSTANT_NAME` and optionally th
525
553
 
526
554
  **How To Use:**
527
555
 
528
- expect(instance).to have_constant(:FOO)
556
+ expect(instance).to have_constant(:FOO)
529
557
 
530
- expect(instance).to have_constant(:BAR).with_value('Bar')
558
+ expect(instance).to have_constant(:BAR).with_value('Bar')
531
559
 
532
- expect(instance).to have_immutable_constant(:BAZ).with_value('Baz')
560
+ expect(instance).to have_immutable_constant(:BAZ).with_value('Baz')
533
561
 
534
562
  **Parameters:** Constant name. Expects a string or symbol that is a valid identifier.
535
563
 
@@ -619,6 +647,26 @@ Checks if the actual object responds to `#property=`.
619
647
 
620
648
  `option allow_private [Boolean]` Defaults to false. If true, the matcher will also match a private or protected method.
621
649
 
650
+ #### `#watch_value` Helper
651
+
652
+ require 'rspec/sleeping_king_studios/matchers/core/have_changed'
653
+
654
+ Creates a value spy that watches the value of a method call or block. The spy also caches the initial value at the time the spy was created; this allows comparisons between the initial and current values. Value spies are used with the `#have_changed` matcher (see above).
655
+
656
+ **How To Use:**
657
+
658
+ spy = watch_value(object, property)
659
+
660
+ spy = watch_value { object.property }
661
+
662
+ **Parameters:**
663
+
664
+ `param object [Object]` The object to watch. Ignored if given a block.
665
+
666
+ `param method_name [String, Symbol]` The name of the method to watch. Ignored if given a block.
667
+
668
+ **Chaining:** None.
669
+
622
670
  ## Shared Examples
623
671
 
624
672
  To use a custom example group, `require` the associated file and then `include`
@@ -679,9 +727,9 @@ Delegates to the `#have_writer` matcher (see Core/#have_writer, above) and passe
679
727
 
680
728
  Delegates to the `#have_constant` matcher (see Core/#have_constant, above) and passes if the described class defines the specified constant. If a value is specified, the class or module must define the constant with the specified value. Alternatively, you can set a proc as the expected value, which can contain a comparison, an RSpec expectation, or a more complex expression:
681
729
 
682
- include_examples 'should have property', :BAR, ->() { an_instance_of(String) }
730
+ include_examples 'should have constant', :BAR, ->() { an_instance_of(String) }
683
731
 
684
- include_examples 'should have property', :BAZ, ->(value) { value.count = 3 }
732
+ include_examples 'should have constant', :BAZ, ->(value) { value.count = 3 }
685
733
 
686
734
  #### Should Have Immutable Constant
687
735
 
@@ -5,6 +5,13 @@ require 'rspec/core'
5
5
  module RSpec
6
6
  # Hic Iacet Arthurus, Rex Quondam, Rexque Futurus.
7
7
  module SleepingKingStudios
8
+ def self.gem_path
9
+ pattern =
10
+ /#{File::SEPARATOR}lib#{File::SEPARATOR}rspec#{File::SEPARATOR}?\z/
11
+
12
+ __dir__.sub(pattern, '')
13
+ end
14
+
8
15
  def self.version
9
16
  @version ||= RSpec::SleepingKingStudios::Version.to_gem_version
10
17
  end # class method version
@@ -35,6 +35,16 @@ module RSpec::SleepingKingStudios::Concerns
35
35
  raise NameError, message
36
36
  end # class method guard_existing_constant!
37
37
 
38
+ def self.resolve_base_class value
39
+ value = value.fetch(:base_class, nil) if value.is_a?(Hash)
40
+
41
+ return Object if value.nil?
42
+
43
+ return Object.const_get(value) if value.is_a?(String)
44
+
45
+ value
46
+ end
47
+
38
48
  def self.resolve_namespace module_names
39
49
  last_defined = nil
40
50
 
@@ -54,10 +64,11 @@ module RSpec::SleepingKingStudios::Concerns
54
64
  end # if
55
65
  end # class method resolve_namespace
56
66
 
57
- def example_class class_name, base_class: Object, &block
67
+ def example_class class_name, base_class = nil, &block
68
+ class_name = class_name.to_s if class_name.is_a?(Symbol)
69
+
58
70
  example_constant(class_name) do
59
- base_class = Object.const_get(base_class) if base_class.is_a?(String)
60
- klass = Class.new(base_class)
71
+ klass = Class.new(ExampleConstants.resolve_base_class(base_class))
61
72
 
62
73
  klass.define_singleton_method(:name) { class_name }
63
74
  klass.singleton_class.send(:alias_method, :inspect, :name)
@@ -57,7 +57,7 @@ module RSpec::SleepingKingStudios::Concerns
57
57
  # automatically skip such groups.
58
58
  # groups.
59
59
  def xinclude_examples name, *args, **kwargs, &block
60
- xdescribe '(focused)' do
60
+ xdescribe '(skipped)' do
61
61
  if kwargs.empty?
62
62
  include_examples name, *args, &block
63
63
  else
@@ -8,10 +8,10 @@ module RSpec::SleepingKingStudios
8
8
  # Configuration options for RSpec::SleepingKingStudios::Examples.
9
9
  class Examples
10
10
  # Permitted options for :handle_missing_failure_message_with.
11
- MISSING_FAILURE_MESSAGE_HANDLERS = %w(ignore pending exception).map(&:intern)
11
+ MISSING_FAILURE_MESSAGE_HANDLERS = %i[ignore pending exception].freeze
12
12
 
13
13
  # Options for matching failure messages to strings.
14
- STRING_FAILURE_MESSAGE_MATCH_OPTIONS = %w(exact substring).map(&:intern)
14
+ STRING_FAILURE_MESSAGE_MATCH_OPTIONS = %i[exact substring].freeze
15
15
 
16
16
  # Gets the handler for missing failure messages when using the matcher
17
17
  # examples, and sets to :pending if unset.
@@ -30,6 +30,8 @@ module RSpec::SleepingKingStudios
30
30
  # @raise ArgumentError If the handler is not one of the recognized
31
31
  # values.
32
32
  def handle_missing_failure_message_with= value
33
+ value = value.to_s.intern
34
+
33
35
  unless MISSING_FAILURE_MESSAGE_HANDLERS.include?(value)
34
36
  message = "unrecognized handler value -- must be in #{MISSING_FAILURE_MESSAGE_HANDLERS.join ', '}"
35
37
 
@@ -55,6 +57,7 @@ module RSpec::SleepingKingStudios
55
57
  # @raise ArgumentError If the handler is not one of the recognized
56
58
  # values.
57
59
  def match_string_failure_message_as= value
60
+ value = value.to_s.intern
58
61
  value = :substring if value == :partial
59
62
 
60
63
  unless STRING_FAILURE_MESSAGE_MATCH_OPTIONS.include?(value)
@@ -120,21 +123,21 @@ module RSpec::SleepingKingStudios
120
123
  # Get or set the configuration options for
121
124
  # RSpec::SleepingKingStudios::Examples.
122
125
  def examples &block
123
- (@examples ||= RSpec::SleepingKingStudios::Configuration::Examples.new).tap do |config|
124
- if block_given?
125
- config.instance_eval &block
126
- end # if
127
- end # tap
126
+ @examples ||= RSpec::SleepingKingStudios::Configuration::Examples.new
127
+
128
+ @examples.instance_eval(&block) if block_given?
129
+
130
+ @examples
128
131
  end # method examples
129
132
 
130
133
  # Get or set the configuration options for
131
134
  # RSpec::SleepingKingStudios::Matchers.
132
135
  def matchers &block
133
- (@matchers ||= RSpec::SleepingKingStudios::Configuration::Matchers.new).tap do |config|
134
- if block_given?
135
- config.instance_eval &block
136
- end # if
137
- end # tap
136
+ @matchers ||= RSpec::SleepingKingStudios::Configuration::Matchers.new
137
+
138
+ @matchers.instance_eval(&block) if block_given?
139
+
140
+ @matchers
138
141
  end # method matchers
139
142
  end # class
140
143
  end # module
@@ -142,10 +145,10 @@ end # module
142
145
  class RSpec::Core::Configuration
143
146
  # Get or set the configuration options for RSpec::SleepingKingStudios.
144
147
  def sleeping_king_studios &block
145
- (@sleeping_king_studios ||= RSpec::SleepingKingStudios::Configuration.new).tap do |config|
146
- if block_given?
147
- config.instance_eval &block
148
- end # if
149
- end # tap
148
+ @sleeping_king_studios ||= RSpec::SleepingKingStudios::Configuration.new
149
+
150
+ @sleeping_king_studios.instance_eval(&block) if block_given?
151
+
152
+ @sleeping_king_studios
150
153
  end # method sleeping_king_studios
151
154
  end # class
@@ -11,6 +11,21 @@ module RSpec::SleepingKingStudios::Examples
11
11
  module ClassProperties
12
12
  extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
13
13
 
14
+ shared_examples 'should have class property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
15
+ it "should have class property :#{property}" do
16
+ if expected_value == UNDEFINED_VALUE_EXPECTATION
17
+ expect(described_class).to have_property(property)
18
+ else
19
+ expected_value = format_expected_value(expected_value)
20
+
21
+ expect(described_class).to have_property(property).with_value(expected_value)
22
+ end # if-else
23
+ end # it
24
+ end # shared_examples
25
+ alias_shared_examples 'defines class property', 'should have class property'
26
+ alias_shared_examples 'has class property', 'should have class property'
27
+ alias_shared_examples 'should define class property', 'should have class property'
28
+
14
29
  shared_examples 'should have class reader' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
15
30
  it "should have class reader :#{property}" do
16
31
  if expected_value == UNDEFINED_VALUE_EXPECTATION
@@ -22,14 +37,29 @@ module RSpec::SleepingKingStudios::Examples
22
37
  end # if-else
23
38
  end # it
24
39
  end # shared_examples
40
+ alias_shared_examples 'defines class reader', 'should have class reader'
25
41
  alias_shared_examples 'has class reader', 'should have class reader'
42
+ alias_shared_examples 'should define class reader', 'should have class reader'
43
+
44
+ shared_examples 'should have class writer' do |property|
45
+ writer_name = property.to_s.sub /\=\z/, ''
46
+
47
+ it "should have class writer :#{writer_name}" do
48
+ expect(described_class).to have_writer(property)
49
+ end # it
50
+ end # shared_examples
51
+ alias_shared_examples 'defines class writer', 'should have class writer'
52
+ alias_shared_examples 'has class writer', 'should have class writer'
53
+ alias_shared_examples 'should define class writer', 'should have class writer'
26
54
 
27
55
  shared_examples 'should not have class reader' do |property|
28
56
  it "should not have class reader :#{property}" do
29
57
  expect(described_class).not_to have_reader(property)
30
58
  end # it
31
59
  end # shared_examples
60
+ alias_shared_examples 'does not define class reader', 'should not have class reader'
32
61
  alias_shared_examples 'does not have class reader', 'should not have class reader'
62
+ alias_shared_examples 'should not define class reader', 'should not have class reader'
33
63
 
34
64
  shared_examples 'should not have class writer' do |property|
35
65
  writer_name = property.to_s.sub /\=\z/, ''
@@ -38,29 +68,9 @@ module RSpec::SleepingKingStudios::Examples
38
68
  expect(described_class).not_to have_writer(property)
39
69
  end # it
40
70
  end # shared_examples
71
+ alias_shared_examples 'does not define class writer', 'should not have class writer'
41
72
  alias_shared_examples 'does not have class writer', 'should not have class writer'
42
-
43
- shared_examples 'should have class writer' do |property|
44
- writer_name = property.to_s.sub /\=\z/, ''
45
-
46
- it "should have class writer :#{writer_name}" do
47
- expect(described_class).to have_writer(property)
48
- end # it
49
- end # shared_examples
50
- alias_shared_examples 'has class writer', 'should have class writer'
51
-
52
- shared_examples 'should have class property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
53
- it "should have class property :#{property}" do
54
- if expected_value == UNDEFINED_VALUE_EXPECTATION
55
- expect(described_class).to have_property(property)
56
- else
57
- expected_value = format_expected_value(expected_value)
58
-
59
- expect(described_class).to have_property(property).with_value(expected_value)
60
- end # if-else
61
- end # it
62
- end # shared_examples
63
- alias_shared_examples 'has class property', 'should have class property'
73
+ alias_shared_examples 'should not define class writer', 'should not have class writer'
64
74
  end # module
65
75
  end # module
66
76
  end # module