rspec-given 3.5.4 → 3.8.1

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
- SHA1:
3
- metadata.gz: eab60c3e50e50e286389f43541fd90f062a542d8
4
- data.tar.gz: 73e5c1296f3f1a723ac1f87cbe8eb3d338903ec1
2
+ SHA256:
3
+ metadata.gz: 7847253b702f86bbba6c63d3e32354c5f3a33af9955c926992ca76fe06fd6b6d
4
+ data.tar.gz: c205a7847faa2ac00e47840b5a4ffbe88eee54e60c6b00f227082f3391b45a32
5
5
  SHA512:
6
- metadata.gz: deb2cf0765a9ab14901f1752b86e055d710d68962e4c3c33efcad4a957a1cf8f03552e4148220cd7843e9518a4a4ce1dbd5c5d4184cc7447b987e8867eb1b624
7
- data.tar.gz: 361f0d782298dcf2b23e651f20ddb9e27c235127320fdfd29d0e097834381bfea22a52df9ccaaba8b4e082d49c2b984b59f77e7dcc80dbec5b1240970fe344d4
6
+ metadata.gz: f2d90729c20ff4a73f3e52b724a69bb8d76ebc65184d8bc79608f033e71adbf87c934e7660455ee65b7ddc1310b7897098818274fab7ac2fc36f86cb304fa603
7
+ data.tar.gz: 112dc119cc8fd26249c97991d73782d2b13e499fad185b265504b8b425aefcd4fb5de0db4cad42c7f4b804aa516ef3c2ae710cdaae84ad5e94f01800963f511c
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'rspec', '>= 2.12'
4
+ gem 'rspec', ENV['RSPEC_VERSION'] || '>= 2.14.0'
5
5
  gem 'minitest', '>= 4.3'
6
6
  gem 'sorcerer', '>= 0.3.7'
@@ -1,29 +1,32 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.2.5)
5
- minitest (4.3.2)
6
- rake (0.9.6)
7
- rspec (3.0.0.beta2)
8
- rspec-core (= 3.0.0.beta2)
9
- rspec-expectations (= 3.0.0.beta2)
10
- rspec-mocks (= 3.0.0.beta2)
11
- rspec-core (3.0.0.beta2)
12
- rspec-support (= 3.0.0.beta2)
13
- rspec-expectations (3.0.0.beta2)
4
+ diff-lcs (1.4.4)
5
+ minitest (5.14.2)
6
+ rake (13.0.1)
7
+ rspec (3.9.0)
8
+ rspec-core (~> 3.9.0)
9
+ rspec-expectations (~> 3.9.0)
10
+ rspec-mocks (~> 3.9.0)
11
+ rspec-core (3.9.3)
12
+ rspec-support (~> 3.9.3)
13
+ rspec-expectations (3.9.2)
14
14
  diff-lcs (>= 1.2.0, < 2.0)
15
- rspec-support (= 3.0.0.beta2)
16
- rspec-mocks (3.0.0.beta2)
17
- rspec-support (= 3.0.0.beta2)
18
- rspec-support (3.0.0.beta2)
19
- sorcerer (1.0.2)
15
+ rspec-support (~> 3.9.0)
16
+ rspec-mocks (3.9.1)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.9.0)
19
+ rspec-support (3.9.3)
20
+ sorcerer (2.0.1)
20
21
 
21
22
  PLATFORMS
22
- java
23
23
  ruby
24
24
 
25
25
  DEPENDENCIES
26
26
  minitest (>= 4.3)
27
27
  rake
28
- rspec (>= 2.12)
28
+ rspec (>= 2.14.0)
29
29
  sorcerer (>= 0.3.7)
30
+
31
+ BUNDLED WITH
32
+ 2.1.4
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  | Master |
4
4
  | :----: |
5
- | [![Master Build Status](https://secure.travis-ci.org/jimweirich/rspec-given.png?branch=master)](https://travis-ci.org/jimweirich/rspec-given) |
5
+ | [![Master Build Status](https://secure.travis-ci.org/rspec-given/rspec-given.png?branch=master)](https://travis-ci.org/rspec-given/rspec-given) |
6
6
 
7
- Covering rspec-given, minitest-given, and given-core, version 3.5.3.
7
+ Covering rspec-given, minitest-given, and given-core, version 3.8.1.
8
8
 
9
9
  rspec-given and minitest-given are extensions to your favorite testing
10
10
  framework to allow Given/When/Then notation when writing specs.
@@ -27,7 +27,7 @@ The rspec-given gem is the original given/when/then extension for
27
27
  RSpec. It now depends on a given_core gem for the basic functionality
28
28
  and then adds the RSpec specific code.
29
29
 
30
- * rspec-given now requires RSpec version 2.12 or better.
30
+ * rspec-given now requires RSpec version 2.14.0 or better.
31
31
 
32
32
  ### Minitest/Given
33
33
 
@@ -53,7 +53,7 @@ things to watch out for:
53
53
 
54
54
  * Only one before block is allowed in any given Minitest::Spec
55
55
  describe block. This doesn't effect the number of Givens you are
56
- allowed to use, but it may surprise if you are use to RSpec.
56
+ allowed to use, but it may surprise you if you are used to RSpec.
57
57
 
58
58
  ### Auto Selecting
59
59
 
@@ -72,9 +72,9 @@ end
72
72
  ```
73
73
 
74
74
  See
75
- [stack_spec.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/stack/stack_spec.rb)
75
+ [stack_spec.rb](https://github.com/rspec-given/rspec-given/blob/minispec/examples/stack/stack_spec.rb)
76
76
  and
77
- [example_helper.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/example_helper.rb)
77
+ [example_helper.rb](https://github.com/rspec-given/rspec-given/blob/minispec/examples/example_helper.rb)
78
78
 
79
79
  ## Installation
80
80
 
@@ -347,6 +347,17 @@ should use an empty _Then_ clause, like this:
347
347
  Then { }
348
348
  ```
349
349
 
350
+ A _Then_ clause accepts arguments for user-defined RSpec metadata:
351
+
352
+ ```ruby
353
+ Then(:zippy, :foo => 17) { ... }
354
+ ```
355
+
356
+ Metadata on _Then_ clauses is an RSpec-only feature. You can read more about
357
+ metadata [in RSpec's
358
+ documentation](https://www.relishapp.com/rspec/rspec-core/docs/metadata/user-defined-metadata).
359
+
360
+
350
361
  #### Then examples:
351
362
 
352
363
  ```ruby
@@ -760,12 +771,13 @@ _expect_.
760
771
 
761
772
  Given uses the Ripper library to parse the source lines and failing
762
773
  conditions to find all the sub-expression values upon a failure.
763
- Currently Ripper is not supported on Rubinius and versions of JRuby
764
- prior to JRuby-1.7.5.
765
774
 
766
- If you want to use a version of Ruby that does not support Ripper,
767
- then natural assertions will disabled. In addition, you should also
768
- disable source caching in the configuration (see the configuration
775
+ If Ripper is not available, like on Rubinius and versions of JRuby prior to
776
+ JRuby-1.7.5, detailed explanations of failures for natural assertions won't be
777
+ available. Natural assertions will still work, though.
778
+
779
+ If you want to use a version of Ruby that does not support Ripper, then you
780
+ should disable source caching in the configuration (see the configuration
769
781
  section below).
770
782
 
771
783
  ### Non-Spec Assertions
@@ -870,6 +882,26 @@ License. See the MIT-LICENSE file in the source distribution.
870
882
 
871
883
  # History
872
884
 
885
+ * Version 3.8.0
886
+
887
+ * RSpec metadata can now be added to _Then_ clauses (see [#11](https://github.com/rspec-given/rspec-given/pull/11))
888
+ * Natural assertions now run on Rubinius and older versions of JRuby (see [#15](https://github.com/rspec-given/rspec-given/issues/15))
889
+ * WARNING: On these platforms, detailed failure explanations aren't available and source code snippets of Then clauses will only show the first line.
890
+ * WARNING: Assertions of void statements (e.g. `Then { }`) will fail only under runtimes lacking Ripper support
891
+ * `Given.ok_to_use_natural_assertions` was removed; the method was never properly supported as public, but it was publicly reachable
892
+
893
+ * Version 3.7.1
894
+
895
+ * Mixin Minitest extensions for both ActiveSupport::TestCase (when present) as well as for MiniTest::Spec (see [#8](https://github.com/rspec-given/rspec-given/pulls/8))
896
+
897
+ * Version 3.7.0
898
+
899
+ * Add support for Rails tests when using minitest-given (See [#6](https://github.com/rspec-given/rspec-given/pull/6))
900
+
901
+ * Version 3.6.0
902
+
903
+ * Various fixes for RSpec 3.0 (See [#1](https://github.com/rspec-given/rspec-given/pull/1))
904
+
873
905
  * Version 3.5.4
874
906
 
875
907
  * Accommodate the name change on RSpec's Pending exception.
@@ -948,7 +980,7 @@ License. See the MIT-LICENSE file in the source distribution.
948
980
 
949
981
  # Links
950
982
 
951
- * Github: [https://github.com/jimweirich/rspec-given](https://github.com/jimweirich/rspec-given)
952
- * Clone URL: git://github.com/jimweirich/rspec-given.git
953
- * Bug/Issue Reporting: [https://github.com/jimweirich/rspec-given/issues](https://github.com/jimweirich/rspec-given/issues)
954
- * Continuous Integration: [http://travis-ci.org/#!/jimweirich/rspec-given](http://travis-ci.org/#!/jimweirich/rspec-given)
983
+ * Github: [https://github.com/rspec-given/rspec-given](https://github.com/rspec-given/rspec-given)
984
+ * Clone URL: git://github.com/rspec-given/rspec-given.git
985
+ * Bug/Issue Reporting: [https://github.com/rspec-given/rspec-given/issues](https://github.com/rspec-given/rspec-given/issues)
986
+ * Continuous Integration: [http://travis-ci.org/#!/rspec-given/rspec-given](http://travis-ci.org/#!/rspec-given/rspec-given)
data/Rakefile CHANGED
@@ -62,13 +62,10 @@ end
62
62
  EXAMPLES = FileList['examples/**/*_spec.rb', 'examples/use_assertions.rb'].
63
63
  exclude('examples/failing/*.rb').
64
64
  exclude('examples/minitest/*.rb').
65
+ exclude('examples/minitest-rails/*.rb').
65
66
  exclude('examples/integration/failing/*.rb')
66
67
 
67
- MT_EXAMPLES = FileList['examples/minitest/**/*_spec.rb']
68
-
69
- unless Given::NATURAL_ASSERTIONS_SUPPORTED
70
- EXAMPLES.exclude("examples/stack/*.rb")
71
- end
68
+ MT_EXAMPLES = FileList['examples/minitest-rails/**/*_spec.rb', 'examples/minitest/**/*_spec.rb']
72
69
 
73
70
  FAILING_EXAMPLES = FileList['examples/failing/**/*_spec.rb']
74
71
 
@@ -4,4 +4,4 @@ rspec-given is an RSpec extension to allow Given/When/Then notation in
4
4
  RSpec specifications. It is a natural extension of the experimental
5
5
  work done on the Given framework.
6
6
 
7
- For more information see http://github.com/jimweirich/rspec-given
7
+ For more information see http://github.com/rspec-given/rspec-given
@@ -0,0 +1,10 @@
1
+ module ActiveSupport
2
+ class TestCase < Minitest::Test
3
+ # Add spec DSL
4
+ extend ::Minitest::Spec::DSL
5
+
6
+ register_spec_type(self) do |desc, *addl|
7
+ addl.include? :model
8
+ end
9
+ end
10
+ end
@@ -5,6 +5,7 @@ if defined?(RSpec)
5
5
  require 'spec_helper'
6
6
  else
7
7
  require 'minitest/autorun'
8
+ require 'active_support_helper'
8
9
  require 'minitest/given'
9
10
  require 'minitest_helper'
10
11
  end
@@ -2,30 +2,44 @@ require 'example_helper'
2
2
  require 'open3'
3
3
 
4
4
  describe "Failing Messages" do
5
- use_natural_assertions_if_supported
6
-
7
5
  IOS = Struct.new(:out, :err)
8
6
 
9
7
  def run_spec(filename)
10
- inn, out, err, wait = Open3.popen3("rspec", "examples/integration/failing/#{filename}")
8
+ _inn, out, err, _wait = Open3.popen3(
9
+ "rspec", "examples/integration/failing/#{filename}",
10
+ # Ensure our `project_source_dirs` config is set when we shell out to RSpec.
11
+ "-rexample_helper"
12
+ )
11
13
  IOS.new(out.read, err.read)
12
14
  end
13
15
 
14
16
  When(:ios) { run_spec(failing_test) }
15
17
 
16
18
  context "when referencing constants from nested modules" do
19
+ skip_natural_assertions_if_not_supported
17
20
  Given(:failing_test) { "module_nesting_spec.rb" }
18
21
  Then { ios.err == "" }
19
22
  And { ios.out !~ /uninitialized constant RSpec::Given::InstanceExtensions::X/ }
20
23
  end
21
24
 
22
25
  context "when referencing undefined methods" do
26
+ skip_natural_assertions_if_not_supported
23
27
  Given(:failing_test) { "undefined_method_spec.rb" }
24
28
  Then { ios.err == "" }
25
- And { ios.out =~ /undefined local variable or method `xyz'/ }
29
+ And { complains_xyz_is_not_in_scope?(ios.out) }
30
+
31
+ def complains_xyz_is_not_in_scope?(out)
32
+ [
33
+ # RSpec <3.2's message:
34
+ "undefined local variable or method `xyz'",
35
+ # RSpec >3.2's message:
36
+ "`xyz` is not available from within an example"
37
+ ].any? { |msg| out.include?(msg) }
38
+ end
26
39
  end
27
40
 
28
41
  context "when breaking down expressions" do
42
+ skip_natural_assertions_if_not_supported
29
43
  Given(:failing_test) { "eval_subexpression_spec.rb" }
30
44
  Then { ios.err == "" }
31
45
  And { ios.out =~ /false *<- array\[index\]\.upcase == value$/ }
@@ -42,8 +56,9 @@ describe "Failing Messages" do
42
56
  end
43
57
 
44
58
  context "with an oddly formatted then" do
59
+ skip_natural_assertions_if_not_supported
45
60
  Given(:failing_test) { "oddly_formatted_then.rb" }
46
- Then { ios.out =~ /Failure\/Error: Then \{ result == \['a',$/ }
61
+ Then { ios.out =~ /Failure\/Error:\s*Then \{ result == \['a',$/ }
47
62
  And { ios.out =~ /expected: "anything"/ }
48
63
  And { ios.out =~ /to equal: \["a", "a"\]/ }
49
64
  end
@@ -55,8 +55,8 @@ describe "Lazy Givens" do
55
55
  end
56
56
 
57
57
  context "when not called" do
58
- Given(:value) { :ok }
59
- Then { given_assert_equal :ok, value }
58
+ Given(:some_value) { :ok }
59
+ Then { given_assert_equal :ok, some_value }
60
60
  end
61
61
  end
62
62
 
@@ -11,11 +11,10 @@ end
11
11
 
12
12
  describe "Then" do
13
13
  context "empty thens with natural assertions" do
14
- use_natural_assertions_if_supported
14
+ skip_natural_assertions_if_not_supported #<--we can't detect void statements
15
15
  Then { }
16
16
  end
17
17
  context "thens to_bool/true will pass" do
18
- use_natural_assertions_if_supported
19
18
  Then { ToBool.new(true) }
20
19
  end
21
20
  end
@@ -0,0 +1,33 @@
1
+ require 'minitest/autorun'
2
+ require 'active_support_helper'
3
+ require 'minitest/given'
4
+ require 'example_helper'
5
+
6
+
7
+ describe ActiveSupport::TestCase, :model do
8
+ Given(:info) { [] }
9
+ Given { info << "outer1" }
10
+ Given { info << "outer2" }
11
+
12
+ context "using a when without result" do
13
+ When { info << "when" }
14
+
15
+ context "inner with When" do
16
+ Given { info << "inner1" }
17
+ Given { info << "inner2" }
18
+ Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }
19
+
20
+ context "using a nested When" do
21
+ When { info << "when2" }
22
+ Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2"], info}
23
+ end
24
+
25
+ context "using two nested When" do
26
+ When { info << "when2a" }
27
+ When { info << "when2b" }
28
+ Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2a", "when2b"], info }
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -1,4 +1,3 @@
1
-
2
1
  module GivenAssertions
3
2
  def given_assert(cond)
4
3
  assert cond
@@ -23,16 +22,13 @@ module GivenAssertions
23
22
  end
24
23
 
25
24
  module NaturalAssertionControl
26
- def use_natural_assertions_if_supported(enabled=true)
27
- if enabled && ! Given::NATURAL_ASSERTIONS_SUPPORTED
28
- Given {
29
- skip "Natural assertions are not supported in JRuby"
30
- }
31
- else
32
- use_natural_assertions(enabled)
25
+ def skip_natural_assertions_if_not_supported
26
+ if !Given::NATURAL_ASSERTIONS_SUPPORTED
27
+ Given { skip "This test requires a Ruby runtime with full natural assertions support." }
33
28
  end
34
29
  end
35
30
  end
36
31
 
37
32
  Minitest::Spec.send(:include, GivenAssertions)
33
+ Minitest::Test.send(:include, GivenAssertions)
38
34
  include NaturalAssertionControl
@@ -1,47 +1,44 @@
1
1
  require 'given/module_methods'
2
2
 
3
- if Given::NATURAL_ASSERTIONS_SUPPORTED
3
+ require 'given/assertions'
4
+ require 'given/fuzzy_number'
4
5
 
5
- require 'given/assertions'
6
- require 'given/fuzzy_number'
6
+ include Given::Assertions
7
+ include Given::Fuzzy
7
8
 
8
- include Given::Assertions
9
- include Given::Fuzzy
10
-
11
- def sqrt(n)
12
- Precondition { n >= 0 }
13
- result = Math.sqrt(n)
14
- Postcondition { result ** 2 == about(n) }
15
- result
16
- end
9
+ def sqrt(n)
10
+ Precondition { n >= 0 }
11
+ result = Math.sqrt(n)
12
+ Postcondition { result ** 2 == about(n) }
13
+ result
14
+ end
17
15
 
18
- def sqrt_bad_postcondition(n)
19
- Precondition { n >= 0 }
20
- result = Math.sqrt(n)
21
- Postcondition { result ** 2 == about(n+1) }
22
- result
23
- end
16
+ def sqrt_bad_postcondition(n)
17
+ Precondition { n >= 0 }
18
+ result = Math.sqrt(n)
19
+ Postcondition { result ** 2 == about(n+1) }
20
+ result
21
+ end
24
22
 
25
- def use_assert(n)
26
- Assert { n == 1 }
27
- end
23
+ def use_assert(n)
24
+ Assert { n == 1 }
25
+ end
28
26
 
29
- def should_fail
30
- begin
31
- yield
32
- fail "Expected error"
33
- rescue Given::Assertions::AssertError => ex
34
- true
35
- end
27
+ def should_fail
28
+ begin
29
+ yield
30
+ fail "Expected error"
31
+ rescue Given::Assertions::AssertError => ex
32
+ true
36
33
  end
34
+ end
37
35
 
38
- sqrt(1)
39
- sqrt(2)
40
- sqrt(0)
36
+ sqrt(1)
37
+ sqrt(2)
38
+ sqrt(0)
41
39
 
42
- should_fail { sqrt(-1) }
43
- should_fail { sqrt_bad_postcondition(1) }
40
+ should_fail { sqrt(-1) }
41
+ should_fail { sqrt_bad_postcondition(1) }
44
42
 
45
- use_assert(1)
46
- should_fail { use_assert(0) }
47
- end
43
+ use_assert(1)
44
+ should_fail { use_assert(0) }
@@ -48,15 +48,14 @@ EOF
48
48
  ]
49
49
 
50
50
  s.add_dependency("given_core", "= #{Given::VERSION}")
51
- s.add_dependency("rspec", ">= 2.12")
51
+ s.add_dependency("rspec", ">= 2.14.0")
52
52
 
53
53
  s.required_ruby_version = '>= 1.9.2'
54
54
  s.license = "MIT"
55
55
 
56
56
  s.author = "Jim Weirich"
57
57
  s.email = "jim.weirich@gmail.com"
58
- s.homepage = "http://github.com/jimweirich/rspec-given"
59
- s.rubyforge_project = "given"
58
+ s.homepage = "http://github.com/rspec-given/rspec-given"
60
59
  end
61
60
 
62
61
  MINITEST_GIVEN_SPEC = Gem::Specification.new do |s|
@@ -83,8 +82,7 @@ EOF
83
82
 
84
83
  s.author = "Jim Weirich"
85
84
  s.email = "jim.weirich@gmail.com"
86
- s.homepage = "http://github.com/jimweirich/rspec-given"
87
- s.rubyforge_project = "given"
85
+ s.homepage = "http://github.com/rspec-given/rspec-given"
88
86
  end
89
87
 
90
88
  GIVEN_CORE_SPEC = Gem::Specification.new do |s|
@@ -111,8 +109,7 @@ EOF
111
109
 
112
110
  s.author = "Jim Weirich"
113
111
  s.email = "jim.weirich@gmail.com"
114
- s.homepage = "http://github.com/jimweirich/rspec-given"
115
- s.rubyforge_project = "given"
112
+ s.homepage = "http://github.com/rspec-given/rspec-given"
116
113
  end
117
114
 
118
115
  Gem::PackageTask.new(MINITEST_GIVEN_SPEC) do |pkg|
@@ -3,8 +3,6 @@ require 'rspec/given'
3
3
  require 'given/assertions'
4
4
 
5
5
  describe Given::Assertions do
6
- use_natural_assertions_if_supported
7
-
8
6
  Given { extend Given::Assertions }
9
7
 
10
8
  describe "Assert { }" do
@@ -4,7 +4,6 @@ require 'given'
4
4
  require 'given/fuzzy_shortcuts'
5
5
 
6
6
  describe "Numeric Extensions" do
7
- use_natural_assertions_if_supported
8
7
 
9
8
  Given(:n) { 10 }
10
9
  Given(:about_n) { about(n) }
@@ -4,7 +4,6 @@ require 'rspec/given'
4
4
  require 'rspec/given/fuzzy_shortcuts'
5
5
 
6
6
  describe "Numeric Extensions" do
7
- use_natural_assertions_if_supported
8
7
 
9
8
  Given(:n) { 10 }
10
9
  Given(:about_n) { about(n) }
@@ -187,18 +187,25 @@ describe Given::ClassExtensions do
187
187
  And { expect(trace).to eq([:given, :then, :and]) }
188
188
  end
189
189
 
190
+ describe "Adding metadata to Then & And (RSpec 2+)" do
191
+ Given(:test) { RSpec.respond_to?(:current_example) ? RSpec.method(:current_example) : method(:example) }
192
+ Then(:key => :val) { test.call.metadata[:key] == :val }
193
+ And { test.call.metadata[:key] == :val }
194
+
195
+ if rspec_3_or_later?
196
+ describe "Supporting default-to-true metadata symbols (RSpec 3 only)" do
197
+ Then(:magic, :foo => :bar) { test.call.metadata[:magic] == true }
198
+ And { test.call.metadata[:foo] == :bar }
199
+ end
200
+ end
201
+
202
+ end
190
203
  end
191
204
 
192
205
  describe "use_natural_assertions" do
193
- context "when in JRuby" do
194
- CONTEXT = self
206
+ CONTEXT = self
195
207
 
196
- When(:result) { CONTEXT.use_natural_assertions }
208
+ When(:result) { CONTEXT.use_natural_assertions }
197
209
 
198
- if ::Given::NATURAL_ASSERTIONS_SUPPORTED
199
- Then { expect(result).to_not have_failed }
200
- else
201
- Then { expect(result).to have_failed(ArgumentError) }
202
- end
203
- end
210
+ Then { expect(result).to_not have_failed }
204
211
  end
@@ -8,7 +8,6 @@ module FailureMatcherSpec
8
8
  NotMetError = RSpec::Expectations::ExpectationNotMetError
9
9
 
10
10
  describe Given::FailureMatcher do
11
- use_natural_assertions_if_supported
12
11
 
13
12
  Given(:error) { CustomError.new("CUSTOM") }
14
13
 
@@ -21,27 +21,24 @@ describe Given::Failure do
21
21
  end
22
22
 
23
23
  describe "raising error" do
24
- Then { expect(failure).to raise_error(StandardError, "Oops") }
25
- Then { expect(failure).to raise_error(StandardError) }
26
- Then { expect(failure).to raise_error }
24
+ Then { expect { failure.call }.to raise_error(StandardError, "Oops") }
25
+ Then { expect { failure.call }.to raise_error(StandardError) }
26
+ Then { expect { failure.call }.to raise_error }
27
27
  end
28
28
 
29
29
  describe "== have_failed" do
30
- use_natural_assertions_if_supported
31
30
  Then { failure == have_failed(StandardError, "Oops") }
32
31
  Then { failure == have_failed(StandardError) }
33
32
  Then { failure == have_failed }
34
33
  end
35
34
 
36
35
  describe "== Failure" do
37
- use_natural_assertions_if_supported
38
36
  Then { failure == Failure(StandardError, "Oops") }
39
37
  Then { failure == Failure(StandardError) }
40
38
  Then { failure == Failure() }
41
39
  end
42
40
 
43
41
  describe "!= Failure" do
44
- use_natural_assertions_if_supported
45
42
  Then { expect { failure != Object.new }.to raise_error(StandardError) }
46
43
  Then { failure != Failure(other_error) }
47
44
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Given::Fuzzy::FuzzyNumber do
4
- use_natural_assertions_if_supported
5
4
  include Given::Fuzzy
6
5
 
7
6
  describe "attributes" do
@@ -9,7 +9,7 @@ module HaveFailedSpec
9
9
  context "with a failure" do
10
10
  When(:result) { fail CustomError, "Ouch" }
11
11
 
12
- Then { expect(result).to raise_error(CustomError, "Ouch") }
12
+ Then { expect { result.call }.to raise_error(CustomError, "Ouch") }
13
13
  Then { expect(result).to have_failed(CustomError, "Ouch") }
14
14
  Then { expect(result).to have_raised(CustomError, "Ouch") }
15
15
 
@@ -23,10 +23,10 @@ module HaveFailedSpec
23
23
  context "with a standard failure" do
24
24
  When(:result) { fail "Ouch" }
25
25
 
26
- Then { expect(result).to raise_error(StandardError, "Ouch") }
27
- Then { expect(result).to raise_error(StandardError, /^O/) }
28
- Then { expect(result).to raise_error(StandardError) }
29
- Then { expect(result).to raise_error }
26
+ Then { expect { result.call }.to raise_error(StandardError, "Ouch") }
27
+ Then { expect { result.call }.to raise_error(StandardError, /^O/) }
28
+ Then { expect { result.call }.to raise_error(StandardError) }
29
+ Then { expect { result.call }.to raise_error }
30
30
 
31
31
  Then { expect(result).to have_failed(StandardError, "Ouch") }
32
32
  Then { expect(result).to have_failed(StandardError, /^O/) }
@@ -39,12 +39,19 @@ module HaveFailedSpec
39
39
  Then { expect { expect(result).to have_failed(DifferentError) }.to raise_error(ExpectationError) }
40
40
  end
41
41
 
42
- context "with a pending exception" do
43
- def pending_error
42
+ context "with a skip exception" do
43
+ # `skip` replaces old `pending` behavior in RSpec < 3
44
+ # Details: http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3
45
+ def skip_error
44
46
  RSpec::Given::Framework.new.pending_error
45
47
  end
46
- When(:result) { fail pending_error, "Required pending in example ... please ignore" }
47
- Then { Given.fail_with "This example should have been pending" }
48
+ When(:result) { fail skip_error, "Used `skip` in example ... please ignore" }
49
+ Then { Given.fail_with "This example should have been skipped" }
50
+ end
51
+
52
+ context "with a pending invocation" do
53
+ When(:result) { pending "Forcing a pending in example ... please ignore" }
54
+ Then { Given.fail_with "This example should have been regarded as pending" }
48
55
  end
49
56
 
50
57
  context "with a non-failure" do
@@ -54,7 +61,6 @@ module HaveFailedSpec
54
61
  end
55
62
 
56
63
  context "with natural assertions" do
57
- use_natural_assertions_if_supported
58
64
 
59
65
  context "with failure" do
60
66
  When(:result) { fail CustomError, "Ouch" }
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  LEXICAL_PURITY_GLOBAL_CONSTANT = 3
4
4
 
5
5
  describe "Lexical Purity" do
6
- use_natural_assertions_if_supported
7
6
 
8
7
  A = 1
9
8
  Given(:avalue) { 1 }
@@ -44,6 +44,7 @@ module Given
44
44
  end
45
45
 
46
46
  context "when the Then is split over several lines with {}" do
47
+ skip_natural_assertions_if_not_supported
47
48
  Given(:input) {
48
49
  "describe 'foobar' do\n" +
49
50
  " Then {\n" +
@@ -55,6 +56,7 @@ module Given
55
56
  end
56
57
 
57
58
  context "when the Then is has blank lines" do
59
+ skip_natural_assertions_if_not_supported
58
60
  Given(:input) {
59
61
  "describe 'foobar' do\n" +
60
62
  " Then {\n\n" +
@@ -66,6 +68,7 @@ module Given
66
68
  end
67
69
 
68
70
  context "when the Then is split over several lines with do/end" do
71
+ skip_natural_assertions_if_not_supported
69
72
  Given(:input) {
70
73
  "describe 'foobar' do\n" +
71
74
  " Then do\n" +
@@ -77,6 +80,7 @@ module Given
77
80
  end
78
81
 
79
82
  context "when the Then is oddly formatted" do
83
+ skip_natural_assertions_if_not_supported
80
84
  Given(:input) {
81
85
  "describe 'foobar' do\n" +
82
86
  " Then { result == ['a',\n" +
@@ -1,13 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "RSpec::Given.use_natural_assertions" do
4
- context "when in JRuby" do
5
- When(:result) { ::Given.use_natural_assertions }
4
+ When(:result) { ::Given.use_natural_assertions }
6
5
 
7
- if ::Given::NATURAL_ASSERTIONS_SUPPORTED
8
- Then { expect(result).to_not have_failed }
9
- else
10
- Then { expect(result).to have_failed(ArgumentError) }
11
- end
12
- end
6
+ Then { expect(result).to_not have_failed }
13
7
  end
@@ -1,13 +1,19 @@
1
1
  require 'rspec/given'
2
2
  require 'spec_helper'
3
3
 
4
- describe Given::NaturalAssertion do
5
- before do
6
- pending "Natural Assertions disabled for JRuby" unless Given::NATURAL_ASSERTIONS_SUPPORTED
4
+ describe Given::NATURAL_ASSERTIONS_SUPPORTED do
5
+ if (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx') || (defined?(JRUBY_VERSION) &&
6
+ Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('1.7.5'))
7
+ Then { Given::NATURAL_ASSERTIONS_SUPPORTED == false }
8
+ else
9
+ Then { Given::NATURAL_ASSERTIONS_SUPPORTED == true }
7
10
  end
11
+ end
8
12
 
13
+ describe Given::NaturalAssertion do
9
14
  describe "#content?" do
10
15
  context "with empty block" do
16
+ skip_natural_assertions_if_not_supported
11
17
  FauxThen { }
12
18
  Then { expect(na).to_not have_content }
13
19
  end
@@ -42,6 +48,7 @@ describe Given::NaturalAssertion do
42
48
  end
43
49
 
44
50
  describe "failure messages" do
51
+ skip_natural_assertions_if_not_supported
45
52
  let(:msg) { na.message }
46
53
  Invariant { expect(msg).to match(/^FauxThen expression/) }
47
54
 
@@ -56,7 +63,7 @@ describe Given::NaturalAssertion do
56
63
 
57
64
  context "with equals assertion with do/end" do
58
65
  Given(:a) { 1 }
59
- FauxThen do a == 2 end
66
+ FauxThen { a == 2 }
60
67
  Then { expect(msg).to match(/\bexpected: +1\b/) }
61
68
  Then { expect(msg).to match(/\bto equal: +2\b/) }
62
69
  Then { expect(msg).to match(/\bfalse +<- +a == 2\b/) }
@@ -167,7 +174,11 @@ describe Given::NaturalAssertion do
167
174
  ary[1] == 3
168
175
  }
169
176
  When(:result) { na.message }
170
- Then { expect(result).to have_failed(Given::InvalidThenError, /multiple.*statements/i) }
177
+ if Given::NATURAL_ASSERTIONS_SUPPORTED
178
+ Then { expect(result).to have_failed(Given::InvalidThenError, /multiple.*statements/i) }
179
+ else
180
+ Then { expect(result).to match(/FauxThen expression failed/) }
181
+ end
171
182
  end
172
183
 
173
184
  end
@@ -24,12 +24,6 @@ describe "Configuration Options" do
24
24
  end
25
25
 
26
26
  describe "Global natural assertion configuration" do
27
- unless Given::NATURAL_ASSERTIONS_SUPPORTED
28
- before do
29
- pending "Natural assertions are not supported in JRuby"
30
- end
31
- end
32
-
33
27
  before do
34
28
  Given.use_natural_assertions false
35
29
  end
@@ -46,7 +40,7 @@ describe "Configuration Options" do
46
40
  Then { expect(_gvn_need_na_message?(nassert)).to be_falsy }
47
41
 
48
42
  context "overridden locally" do
49
- use_natural_assertions_if_supported
43
+ use_natural_assertions
50
44
  Then { expect(_gvn_need_na_message?(nassert)).to be_truthy }
51
45
  end
52
46
  end
@@ -120,7 +114,7 @@ describe "Configuration Options" do
120
114
  Then { expect(_gvn_need_na_message?(nassert)).to be_falsy }
121
115
 
122
116
  context "overridden locally" do
123
- use_natural_assertions_if_supported(true)
117
+ use_natural_assertions
124
118
  Then { expect(_gvn_need_na_message?(nassert)).to be_truthy }
125
119
  end
126
120
 
@@ -1,4 +1,12 @@
1
1
  require 'rspec/given'
2
+ RSpec.configure do |config|
3
+ # Before RSpec 3.4, RSpec would only print lines in failures from spec files.
4
+ # Starting in 3.4, it now prints lines from the new `project_source_dirs` config
5
+ # setting. We want it to print lines from our specs instead of printing
6
+ # `::RSpec::Expectations.fail_with(*args)` from within lib/given/rspec/framework.rb,
7
+ # so we remove `lib` from the directories here.
8
+ config.project_source_dirs -= ["lib"] if config.respond_to?(:project_source_dirs)
9
+ end
2
10
 
3
11
  # Load the support modules.
4
12
 
@@ -26,3 +34,7 @@ end
26
34
  def given_assert_raises(error, pattern=nil, &block)
27
35
  expect(&block).to raise_error(error, pattern)
28
36
  end
37
+
38
+ def rspec_3_or_later?
39
+ Gem::Version.new(RSpec::Version::STRING).segments[0] >= 3
40
+ end
@@ -1,15 +1,9 @@
1
1
  module NaturalAssertionControl
2
- def use_natural_assertions_if_supported(enabled=true)
3
- if enabled && ! Given::NATURAL_ASSERTIONS_SUPPORTED
4
- Given {
5
- pending "Natural assertions are not supported in JRuby"
6
- }
7
- else
8
- use_natural_assertions(enabled)
2
+ def skip_natural_assertions_if_not_supported
3
+ if !Given::NATURAL_ASSERTIONS_SUPPORTED
4
+ Given { pending "This test requires a Ruby runtime with full natural assertions support." }
9
5
  end
10
6
  end
11
7
  end
12
8
 
13
- RSpec.configure do |c|
14
- c.extend(NaturalAssertionControl)
15
- end
9
+ RSpec.configure { |c| c.extend(NaturalAssertionControl) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-given
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.4
4
+ version: 3.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: given_core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.5.4
19
+ version: 3.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.5.4
26
+ version: 3.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.12'
33
+ version: 2.14.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.12'
40
+ version: 2.14.0
41
41
  description: |
42
42
  Given is an RSpec extension that allows the use of Given/When/Then
43
43
  terminology when defining specifications.
@@ -54,6 +54,7 @@ files:
54
54
  - TODO
55
55
  - doc/article/custom_error_messages.md
56
56
  - doc/main.rdoc
57
+ - examples/active_support_helper.rb
57
58
  - examples/example_helper.rb
58
59
  - examples/failing/natural_failing_spec.rb
59
60
  - examples/failing/sample_spec.rb
@@ -69,6 +70,7 @@ files:
69
70
  - examples/integration/invariant_spec.rb
70
71
  - examples/integration/then_spec.rb
71
72
  - examples/loader.rb
73
+ - examples/minitest-rails/test_case_spec.rb
72
74
  - examples/minitest/assert_raises_spec.rb
73
75
  - examples/minitest_helper.rb
74
76
  - examples/other/line_example.rb
@@ -105,11 +107,11 @@ files:
105
107
  - spec/support/failure_and_errors.rb
106
108
  - spec/support/faux_then.rb
107
109
  - spec/support/natural_assertion_control.rb
108
- homepage: http://github.com/jimweirich/rspec-given
110
+ homepage: http://github.com/rspec-given/rspec-given
109
111
  licenses:
110
112
  - MIT
111
113
  metadata: {}
112
- post_install_message:
114
+ post_install_message:
113
115
  rdoc_options:
114
116
  - "--line-numbers"
115
117
  - "--inline-source"
@@ -130,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
132
  - !ruby/object:Gem::Version
131
133
  version: '0'
132
134
  requirements: []
133
- rubyforge_project: given
134
- rubygems_version: 2.2.0
135
- signing_key:
135
+ rubygems_version: 3.1.2
136
+ signing_key:
136
137
  specification_version: 4
137
138
  summary: Given/When/Then Specification Extensions for RSpec.
138
139
  test_files: []