rspec-its 1.3.1 → 2.0.0

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.
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RSpec
2
4
  module Its
3
- VERSION = "1.3.1"
5
+ VERSION = '2.0.0'
4
6
  end
5
7
  end
data/lib/rspec/its.rb CHANGED
@@ -1,26 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/its/subject'
1
4
  require 'rspec/its/version'
2
5
  require 'rspec/core'
3
6
 
4
7
  RSpec::Core::ExampleGroup.define_example_method :__its_example
5
8
 
6
9
  module RSpec
10
+ # Adds the `its` to RSpec Example Groups, included by default.
7
11
  module Its
8
-
9
12
  # Creates a nested example group named by the submitted `attribute`,
10
13
  # and then generates an example using the submitted block.
11
14
  #
12
15
  # @example
13
16
  #
14
17
  # # This ...
15
- # describe Array do
16
- # its(:size) { should eq(0) }
18
+ # RSpec.describe Array do
19
+ # its(:size) { is_expected.to eq(0) }
17
20
  # end
18
21
  #
19
22
  # # ... generates the same runtime structure as this:
20
- # describe Array do
23
+ # RSpec.describe Array do
21
24
  # describe "size" do
22
- # it "should eq(0)" do
23
- # subject.size.should eq(0)
25
+ # it "is_expected.to eq(0)" do
26
+ # expect(subject.size).to eq(0)
24
27
  # end
25
28
  # end
26
29
  # end
@@ -31,14 +34,14 @@ module RSpec
31
34
  #
32
35
  # @example
33
36
  #
34
- # describe Person do
35
- # subject do
37
+ # RSpec.describe Person do
38
+ # subject(:person) do
36
39
  # Person.new.tap do |person|
37
40
  # person.phone_numbers << "555-1212"
38
41
  # end
39
42
  # end
40
43
  #
41
- # its("phone_numbers.first") { should eq("555-1212") }
44
+ # its("phone_numbers.first") { is_expected.to eq("555-1212") }
42
45
  # end
43
46
  #
44
47
  # When the subject is a `Hash`, you can refer to the Hash keys by
@@ -46,30 +49,30 @@ module RSpec
46
49
  #
47
50
  # @example
48
51
  #
49
- # describe "a configuration Hash" do
52
+ # RSpec.describe "a configuration Hash" do
50
53
  # subject do
51
54
  # { :max_users => 3,
52
55
  # 'admin' => :all_permissions.
53
56
  # 'john_doe' => {:permissions => [:read, :write]}}
54
57
  # end
55
58
  #
56
- # its([:max_users]) { should eq(3) }
57
- # its(['admin']) { should eq(:all_permissions) }
58
- # its(['john_doe', :permissions]) { should eq([:read, :write]) }
59
+ # its([:max_users]) { is_expected.to eq(3) }
60
+ # its(['admin']) { is_expected.to eq(:all_permissions) }
61
+ # its(['john_doe', :permissions]) { are_expected.to eq([:read, :write]) }
59
62
  #
60
63
  # # You can still access its regular methods this way:
61
- # its(:keys) { should include(:max_users) }
62
- # its(:count) { should eq(2) }
64
+ # its(:keys) { is_expected.to include(:max_users) }
65
+ # its(:count) { is_expected.to eq(2) }
63
66
  # end
64
67
  #
65
- # With an implicit subject, `is_expected` can be used as an alternative
66
- # to `should` (e.g. for one-liner use). An `are_expected` alias is also
68
+ # With an implicit subject, `should` can be used as an alternative
69
+ # to `is_expected` (e.g. for one-liner use). An `are_expected` alias is also
67
70
  # supplied.
68
71
  #
69
72
  # @example
70
73
  #
71
- # describe Array do
72
- # its(:size) { is_expected.to eq(0) }
74
+ # RSpec.describe Array do
75
+ # its(:size) { should eq(0) }
73
76
  # end
74
77
  #
75
78
  # With an implicit subject, `will` can be used as an alternative
@@ -77,7 +80,7 @@ module RSpec
77
80
  #
78
81
  # @example
79
82
  #
80
- # describe Array do
83
+ # RSpec.describe Array do
81
84
  # its(:foo) { will raise_error(NoMethodError) }
82
85
  # end
83
86
  #
@@ -86,7 +89,7 @@ module RSpec
86
89
  #
87
90
  # @example
88
91
  #
89
- # describe Array do
92
+ # RSpec.describe Array do
90
93
  # its(:size) { will_not raise_error }
91
94
  # end
92
95
  #
@@ -96,15 +99,15 @@ module RSpec
96
99
  # @example
97
100
  #
98
101
  # # This ...
99
- # describe Array do
100
- # its(:size, :focus) { should eq(0) }
102
+ # RSpec.describe Array do
103
+ # its(:size, :focus) { is_expected.to eq(0) }
101
104
  # end
102
105
  #
103
106
  # # ... generates the same runtime structure as this:
104
- # describe Array do
107
+ # RSpec.describe Array do
105
108
  # describe "size" do
106
- # it "should eq(0)", :focus do
107
- # subject.size.should eq(0)
109
+ # it "is expected to eq(0)", :focus do
110
+ # expect(subject.size).to eq(0)
108
111
  # end
109
112
  # end
110
113
  # end
@@ -115,70 +118,56 @@ module RSpec
115
118
  #
116
119
  # @example
117
120
  #
118
- # describe Person do
121
+ # RSpec.describe Person do
119
122
  # subject { Person.new }
123
+ #
120
124
  # before { subject.age = 25 }
121
- # its(:age) { should eq(25) }
125
+ #
126
+ # its(:age) { is_expected.to eq(25) }
122
127
  # end
123
128
  def its(attribute, *options, &block)
124
- its_caller = caller.select {|file_line| file_line !~ %r(/lib/rspec/its) }
125
- describe(attribute.to_s, :caller => its_caller) do
126
- let(:__its_subject) do
127
- if Array === attribute
128
- if Hash === subject
129
- attribute.inject(subject) {|inner, attr| inner[attr] }
130
- else
131
- subject[*attribute]
132
- end
133
- else
134
- attribute_chain = attribute.to_s.split('.')
135
- attribute_chain.inject(subject) do |inner_subject, attr|
136
- inner_subject.send(attr)
137
- end
138
- end
139
- end
129
+ its_caller = caller.grep_v(%r{/lib/rspec/its})
130
+
131
+ describe(attribute.to_s, caller: its_caller) do
132
+ let(:__its_subject) { RSpec::Its::Subject.for(attribute, subject) }
140
133
 
141
134
  def is_expected
142
135
  expect(__its_subject)
143
136
  end
144
137
  alias_method :are_expected, :is_expected
145
138
 
146
- def will(matcher=nil, message=nil)
147
- unless matcher.supports_block_expectations?
148
- raise ArgumentError, "`will` only supports block expectations"
149
- end
139
+ def will(matcher = nil, message = nil)
140
+ raise ArgumentError, "`will` only supports block expectations" unless matcher.supports_block_expectations?
141
+
150
142
  expect { __its_subject }.to matcher, message
151
143
  end
152
144
 
153
- def will_not(matcher=nil, message=nil)
154
- unless matcher.supports_block_expectations?
155
- raise ArgumentError, "`will_not` only supports block expectations"
156
- end
145
+ def will_not(matcher = nil, message = nil)
146
+ raise ArgumentError, "`will_not` only supports block expectations" unless matcher.supports_block_expectations?
147
+
157
148
  expect { __its_subject }.to_not matcher, message
158
149
  end
159
150
 
160
- def should(matcher=nil, message=nil)
151
+ def should(matcher = nil, message = nil)
161
152
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(__its_subject, matcher, message)
162
153
  end
163
154
 
164
- def should_not(matcher=nil, message=nil)
155
+ def should_not(matcher = nil, message = nil)
165
156
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(__its_subject, matcher, message)
166
157
  end
167
158
 
168
- options << {} unless options.last.kind_of?(Hash)
169
- options.last.merge!(:caller => its_caller)
159
+ options << {} unless options.last.is_a?(Hash)
160
+ options.last.merge!(caller: its_caller)
170
161
 
171
162
  __its_example(nil, *options, &block)
172
-
173
163
  end
174
164
  end
175
-
176
165
  end
177
166
  end
178
167
 
179
168
  RSpec.configure do |rspec|
180
169
  rspec.extend RSpec::Its
181
- rspec.backtrace_exclusion_patterns << %r(/lib/rspec/its)
170
+ rspec.backtrace_exclusion_patterns << %r{/lib/rspec/its}
182
171
  end
183
172
 
184
173
  RSpec::SharedContext.send(:include, RSpec::Its)
data/rspec-its.gemspec CHANGED
@@ -1,49 +1,31 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'rspec/its/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "rspec-its"
8
9
  spec.version = RSpec::Its::VERSION
9
- spec.authors = ["Peter Alfvin"]
10
- spec.email = ["palfvin@gmail.com"]
11
- spec.description = %q{RSpec extension gem for attribute matching}
12
- spec.summary = %q{Provides "its" method formerly part of rspec-core}
10
+ spec.authors = ["The RSpec Development Team"]
11
+ spec.email = ["maintainers@rspec.info"]
12
+ spec.description = 'RSpec extension gem for attribute matching'
13
+ spec.summary = 'Provides "its" method formerly part of rspec-core'
13
14
  spec.homepage = "https://github.com/rspec/rspec-its"
14
15
  spec.license = "MIT"
16
+ spec.required_ruby_version = '> 3.0.0'
15
17
 
16
- spec.metadata = {
17
- 'bug_tracker_uri' => 'https://github.com/rspec/rspec-its/issues',
18
- 'changelog_uri' => "https://github.com/rspec/rspec-its/blob/v#{spec.version}/Changelog.md",
19
- 'documentation_uri' => "https://www.rubydoc.info/gems/rspec-its/#{spec.version}",
20
- 'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/rspec',
21
- 'source_code_uri' => 'https://github.com/rspec/rspec-its',
22
- }
18
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/rspec/rspec-its/issues'
19
+ spec.metadata['changelog_uri'] = "https://github.com/rspec/rspec-its/blob/v#{spec.version}/Changelog.md"
20
+ spec.metadata['documentation_uri'] = "https://www.rubydoc.info/gems/rspec-its/#{spec.version}"
21
+ spec.metadata['mailing_list_uri'] = 'https://groups.google.com/forum/#!forum/rspec'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+ spec.metadata['source_code_uri'] = 'https://github.com/rspec/rspec-its'
23
24
 
24
25
  spec.files = `git ls-files`.split($/) - %w[cucumber.yml]
25
26
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_runtime_dependency 'rspec-core', '>= 3.0.0'
30
- spec.add_runtime_dependency 'rspec-expectations', '>= 3.0.0'
31
-
32
- if RUBY_VERSION.to_f < 1.9 || RUBY_VERSION == '1.9.2'
33
- spec.add_development_dependency "rake", "~> 10.0.0"
34
- elsif RUBY_VERSION.to_f < 2
35
- spec.add_development_dependency "rake", "~> 11.0.0"
36
- elsif RUBY_VERSION.to_f < 2.3
37
- spec.add_development_dependency "rake", "~> 12.3.2"
38
- else
39
- spec.add_development_dependency "rake", "~> 13.0.0"
40
- end
41
-
42
- spec.add_development_dependency 'bundler', '> 1.3.0'
43
- if RUBY_VERSION.to_f < 2
44
- spec.add_development_dependency 'cucumber', '< 3.0.0'
45
- else
46
- spec.add_development_dependency 'cucumber', '>= 1.3.8'
47
- end
48
- spec.add_development_dependency "aruba", "~> 0.14.12"
29
+ spec.add_dependency 'rspec-core', '>= 3.13.0'
30
+ spec.add_dependency 'rspec-expectations', '>= 3.13.0'
49
31
  end
data/script/test_all CHANGED
@@ -21,16 +21,14 @@ else
21
21
  echo "Using $BRANCH"
22
22
  fi
23
23
 
24
- if ruby -e 'exit(ENV.fetch("BRANCH") =~ /3-[0-8]-maintenance/ ? 0 : 1)'; then
25
- TAGS="--tags @pre-3-9"
26
- else
27
- TAGS="--tags @post-3-9"
28
- fi;
29
-
30
24
  if ruby -e "exit(defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java')"; then
31
25
  # This is JRUBY which requires this one weird path trick...
32
26
  PATH="${PWD}/bin:$PATH" \
33
- bundle exec cucumber --strict $TAGS
27
+ bundle exec cucumber --strict
28
+ elif ruby -e "exit(RUBY_VERSION.to_f >= 3.4)"; then
29
+ # This is a monkey patch to fix an issue with cucumber using outdated hash syntax, remove when cucumber is updated or ruby 3.4 released
30
+ sed -i '$i\class Hash; alias :__initialize :initialize; def initialize(*args, **_kw, &block) = __initialize(*args, &block); end' bin/cucumber
31
+ bin/cucumber --strict
34
32
  else
35
- bundle exec cucumber --strict $TAGS
33
+ bundle exec cucumber --strict
36
34
  fi;
@@ -1,35 +1,7 @@
1
1
  #!/bin/bash
2
- # This file was generated on 2019-01-03T20:34:23+00:00 from the rspec-dev repo.
3
- # DO NOT modify it by hand as your changes will get lost the next time it is generated.
4
2
 
5
3
  set -e
6
4
 
7
- function is_ruby_31_plus {
8
- if ruby -e "exit(RUBY_VERSION.to_f >= 3.1)"; then
9
- return 0
10
- else
11
- return 1
12
- fi
13
- }
14
-
15
- function is_ruby_23_plus {
16
- if ruby -e "exit(RUBY_VERSION.to_f >= 2.3)"; then
17
- return 0
18
- else
19
- return 1
20
- fi
21
- }
22
-
23
- if is_ruby_31_plus; then
24
- echo "Installing rubygems 3.3.6 / bundler 2.3.6"
25
- yes | gem update --system '3.3.6'
26
- yes | gem install bundler -v '2.3.6'
27
- elif is_ruby_23_plus; then
28
- echo "Installing rubygems 3.2.22 / bundler 2.2.22"
29
- yes | gem update --system '3.2.22'
30
- yes | gem install bundler -v '2.2.22'
31
- else
32
- echo "Warning installing older versions of Rubygems / Bundler"
33
- gem update --system '2.7.8'
34
- gem install bundler -v '1.17.3'
35
- fi
5
+ echo "Installing latest rubygems / bundler"
6
+ yes | gem update --system
7
+ yes | gem install bundler