Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep rspec-given alive! #52

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
be0b142
Pass super() a Proc instead of Failure object
ronen Jun 5, 2014
545c797
Fixes a slight problem in @ronen's patch
searls Jan 9, 2015
cb54550
Pass `expect` a block when matching `raise_error`
searls Jan 9, 2015
2c58bf8
add a build matrix for rails 2 & 3 simultaneously
searls Jan 9, 2015
4ab4e9f
Change minimum supported rspec version to 2.14.0
searls Jan 9, 2015
227a024
Specify exactly jruby 1.7.9, last known working v.
searls Jan 9, 2015
850aa13
Update specs based on 3.0's 'pending' vs. 'skip'
searls Jan 9, 2015
5a8a298
Merge pull request #1 from rspec-given/rspec3-support
searls Jan 9, 2015
882a01e
3.6.0
searls Jan 9, 2015
678b642
Support minitest-given use in Rails tests
searls Feb 15, 2015
e077508
Merge pull request #6 from rspec-given/fix-minitest-rails
searls Feb 15, 2015
1888287
Fix the build for RSpec 3.2 & higher
searls Jun 30, 2015
fc3af46
Fix a new error case added to Minitest
searls Jun 30, 2015
1e09735
Make the test pass for all rspecs
searls Jun 30, 2015
916cb64
Merge pull request #10 from rspec-given/9-fix-the-build
searls Jun 30, 2015
66dbb5f
3.7.0
searls Feb 15, 2015
fb52c43
Change the way minitest-given is loaded for AR models and non-AR mode…
markj9 Jun 29, 2015
470eda1
Modify before extensions to work for TestCase.
markj9 Jun 30, 2015
74a0788
Add test to support Given with ActiveSupport::TestCase.
markj9 Jul 1, 2015
e57b705
Remove test helper code that isn't really necessary in order to verify
markj9 Jul 3, 2015
b257a61
Keep the Minitest before implementation to itself
searls Jul 8, 2015
9e7dd2d
Refactor for consistency & remove duplication
searls Jul 8, 2015
976850f
Merge pull request #8 from markj9/minitest-given-fix
searls Jul 8, 2015
9dce340
3.7.1
searls Jul 8, 2015
7060efa
Accept user-defined rspec metadata on Then clauses
ronen Jul 17, 2015
523ec36
Add natural assertions support for JRuby 1.7.10 and higher
jkowens Nov 3, 2015
0907416
fix warning
joevandyk Dec 5, 2015
f1d0107
Merge pull request #14 from joevandyk/patch-2
searls Jan 11, 2016
d12a1e4
Merge pull request #13 from jkowens/master
searls Jan 11, 2016
e89abc0
Fix failures in `failing_messages_spec.rb`.
myronmarston Jan 12, 2016
a77e8ed
It's sufficient to only configure spec_helper here
searls Jan 13, 2016
1a4321e
Bump travis to test against the latest rubby
searls Jan 13, 2016
6f7faa6
opt-in to travis's container-based infrastructure
searls Jan 13, 2016
54fbd18
Merge branch 'then-metadata' of https://github.com/ronen/rspec-given …
searls Jan 13, 2016
f15bb51
Isolate branching & reworking the metadata spec
searls Jan 13, 2016
66a12cf
update readme
searls Jan 13, 2016
9453afd
Merge pull request #21 from rspec-given/ruby-2-3
searls Jan 13, 2016
3d28501
fix typo
paddor Dec 23, 2015
33d195b
support Rubinius and old JRuby
paddor Dec 23, 2015
00d65a4
rip out unnecessary natural assertions support checking
paddor Dec 23, 2015
429ef28
update README for new support for natural assertions on Rubinius and …
paddor Dec 23, 2015
7a242af
make it possible to use this gem from git
paddor Dec 27, 2015
1404ba0
Remove ok_to_use_natural_assertions
searls Jan 14, 2016
2774dba
Ignore .ruby-version
searls Jan 14, 2016
6bdd1dd
Restore NATURAL_ASSERTIONS_SUPPORTED constant
searls Jan 14, 2016
5264133
Revert "make it possible to use this gem from git"
searls Jan 14, 2016
f13c685
Add a test for the na support constant
searls Jan 14, 2016
e0f80bc
Get the main specs passing under rbx
searls Jan 14, 2016
10de2a6
w/o ripper, we can't verify an assertion is void
searls Jan 14, 2016
3423cae
Get build passing under rubinius. Add to CI.
searls Jan 14, 2016
f1047a2
Fix for RSpec 3 (which fails if pending passes)
searls Jan 14, 2016
3408ff6
update change log, name next release
searls Jan 14, 2016
9ff92e8
3.8.0
searls Jan 14, 2016
19e9ef2
readme bump
searls Jan 14, 2016
a48301c
Grammar tweaks to readme
jasonkarns May 18, 2018
3df4c60
Merge pull request #27 from jasonkarns/patch-2
searls May 18, 2018
ad82bcd
Fix deprecation warning about eval
searls Oct 5, 2020
3d9a121
fix bundler deprecation
searls Oct 5, 2020
b802074
Fixes a test that broke earlier this year
searls Oct 5, 2020
f9065c1
3.8.1
searls Oct 5, 2020
9eb5659
update readme
searls Oct 5, 2020
22402cb
Restore compatibility for Ruby < 2.6
searls Jan 29, 2021
a6be6cc
3.8.2
searls Jan 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ extra
html
pkg
xxx-*
.bundle
.bundle
.ruby-version
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: ruby
sudo: false
bundler_args: --without dev
env:
- CI=true
- RSPEC_VERSION="2.14.0"
- RSPEC_VERSION=">=3.1.0"
rvm:
- jruby
- rbx-2
- 1.9.3
- 2.0.0
- 2.3.0
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'rake'
gem 'rspec', '>= 2.12'
gem 'rspec', ENV['RSPEC_VERSION'] || '>= 2.14.0'
gem 'minitest', '>= 4.3'
gem 'sorcerer', '>= 0.3.7'
66 changes: 51 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

| Master |
| :----: |
| [![Master Build Status](https://secure.travis-ci.org/jimweirich/rspec-given.png?branch=master)](https://travis-ci.org/jimweirich/rspec-given) |
| [![Master Build Status](https://secure.travis-ci.org/rspec-given/rspec-given.png?branch=master)](https://travis-ci.org/rspec-given/rspec-given) |

Covering rspec-given, minitest-given, and given-core, version 3.5.3.
Covering rspec-given, minitest-given, and given-core, version 3.8.2.

rspec-given and minitest-given are extensions to your favorite testing
framework to allow Given/When/Then notation when writing specs.
Expand All @@ -27,7 +27,7 @@ The rspec-given gem is the original given/when/then extension for
RSpec. It now depends on a given_core gem for the basic functionality
and then adds the RSpec specific code.

* rspec-given now requires RSpec version 2.12 or better.
* rspec-given now requires RSpec version 2.14.0 or better.

### Minitest/Given

Expand All @@ -53,7 +53,7 @@ things to watch out for:

* Only one before block is allowed in any given Minitest::Spec
describe block. This doesn't effect the number of Givens you are
allowed to use, but it may surprise if you are use to RSpec.
allowed to use, but it may surprise you if you are used to RSpec.

### Auto Selecting

Expand All @@ -72,9 +72,9 @@ end
```

See
[stack_spec.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/stack/stack_spec.rb)
[stack_spec.rb](https://github.com/rspec-given/rspec-given/blob/minispec/examples/stack/stack_spec.rb)
and
[example_helper.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/example_helper.rb)
[example_helper.rb](https://github.com/rspec-given/rspec-given/blob/minispec/examples/example_helper.rb)

## Installation

Expand Down Expand Up @@ -347,6 +347,17 @@ should use an empty _Then_ clause, like this:
Then { }
```

A _Then_ clause accepts arguments for user-defined RSpec metadata:

```ruby
Then(:zippy, :foo => 17) { ... }
```

Metadata on _Then_ clauses is an RSpec-only feature. You can read more about
metadata [in RSpec's
documentation](https://www.relishapp.com/rspec/rspec-core/docs/metadata/user-defined-metadata).


#### Then examples:

```ruby
Expand Down Expand Up @@ -760,12 +771,13 @@ _expect_.

Given uses the Ripper library to parse the source lines and failing
conditions to find all the sub-expression values upon a failure.
Currently Ripper is not supported on Rubinius and versions of JRuby
prior to JRuby-1.7.5.

If you want to use a version of Ruby that does not support Ripper,
then natural assertions will disabled. In addition, you should also
disable source caching in the configuration (see the configuration
If Ripper is not available, like on Rubinius and versions of JRuby prior to
JRuby-1.7.5, detailed explanations of failures for natural assertions won't be
available. Natural assertions will still work, though.

If you want to use a version of Ruby that does not support Ripper, then you
should disable source caching in the configuration (see the configuration
section below).

### Non-Spec Assertions
Expand Down Expand Up @@ -870,6 +882,30 @@ License. See the MIT-LICENSE file in the source distribution.

# History

* Version 3.8.1

* Fix deprecation warnings fro Ruby 2.6 & up

* Version 3.8.0

* RSpec metadata can now be added to _Then_ clauses (see [#11](https://github.com/rspec-given/rspec-given/pull/11))
* Natural assertions now run on Rubinius and older versions of JRuby (see [#15](https://github.com/rspec-given/rspec-given/issues/15))
* WARNING: On these platforms, detailed failure explanations aren't available and source code snippets of Then clauses will only show the first line.
* WARNING: Assertions of void statements (e.g. `Then { }`) will fail only under runtimes lacking Ripper support
* `Given.ok_to_use_natural_assertions` was removed; the method was never properly supported as public, but it was publicly reachable

* Version 3.7.1

* 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))

* Version 3.7.0

* Add support for Rails tests when using minitest-given (See [#6](https://github.com/rspec-given/rspec-given/pull/6))

* Version 3.6.0

* Various fixes for RSpec 3.0 (See [#1](https://github.com/rspec-given/rspec-given/pull/1))

* Version 3.5.4

* Accommodate the name change on RSpec's Pending exception.
Expand Down Expand Up @@ -948,7 +984,7 @@ License. See the MIT-LICENSE file in the source distribution.

# Links

* Github: [https://github.com/jimweirich/rspec-given](https://github.com/jimweirich/rspec-given)
* Clone URL: git://github.com/jimweirich/rspec-given.git
* Bug/Issue Reporting: [https://github.com/jimweirich/rspec-given/issues](https://github.com/jimweirich/rspec-given/issues)
* Continuous Integration: [http://travis-ci.org/#!/jimweirich/rspec-given](http://travis-ci.org/#!/jimweirich/rspec-given)
* Github: [https://github.com/rspec-given/rspec-given](https://github.com/rspec-given/rspec-given)
* Clone URL: git://github.com/rspec-given/rspec-given.git
* Bug/Issue Reporting: [https://github.com/rspec-given/rspec-given/issues](https://github.com/rspec-given/rspec-given/issues)
* Continuous Integration: [http://travis-ci.org/#!/rspec-given/rspec-given](http://travis-ci.org/#!/rspec-given/rspec-given)
7 changes: 2 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ end
EXAMPLES = FileList['examples/**/*_spec.rb', 'examples/use_assertions.rb'].
exclude('examples/failing/*.rb').
exclude('examples/minitest/*.rb').
exclude('examples/minitest-rails/*.rb').
exclude('examples/integration/failing/*.rb')

MT_EXAMPLES = FileList['examples/minitest/**/*_spec.rb']

unless Given::NATURAL_ASSERTIONS_SUPPORTED
EXAMPLES.exclude("examples/stack/*.rb")
end
MT_EXAMPLES = FileList['examples/minitest-rails/**/*_spec.rb', 'examples/minitest/**/*_spec.rb']

FAILING_EXAMPLES = FileList['examples/failing/**/*_spec.rb']

Expand Down
2 changes: 1 addition & 1 deletion doc/main.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ rspec-given is an RSpec extension to allow Given/When/Then notation in
RSpec specifications. It is a natural extension of the experimental
work done on the Given framework.

For more information see http://github.com/jimweirich/rspec-given
For more information see http://github.com/rspec-given/rspec-given
10 changes: 10 additions & 0 deletions examples/active_support_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module ActiveSupport
class TestCase < Minitest::Test
# Add spec DSL
extend ::Minitest::Spec::DSL

register_spec_type(self) do |desc, *addl|
addl.include? :model
end
end
end
1 change: 1 addition & 0 deletions examples/example_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'spec_helper'
else
require 'minitest/autorun'
require 'active_support_helper'
require 'minitest/given'
require 'minitest_helper'
end
25 changes: 20 additions & 5 deletions examples/integration/failing_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,44 @@
require 'open3'

describe "Failing Messages" do
use_natural_assertions_if_supported

IOS = Struct.new(:out, :err)

def run_spec(filename)
inn, out, err, wait = Open3.popen3("rspec", "examples/integration/failing/#{filename}")
_inn, out, err, _wait = Open3.popen3(
"rspec", "examples/integration/failing/#{filename}",
# Ensure our `project_source_dirs` config is set when we shell out to RSpec.
"-rexample_helper"
)
IOS.new(out.read, err.read)
end

When(:ios) { run_spec(failing_test) }

context "when referencing constants from nested modules" do
skip_natural_assertions_if_not_supported
Given(:failing_test) { "module_nesting_spec.rb" }
Then { ios.err == "" }
And { ios.out !~ /uninitialized constant RSpec::Given::InstanceExtensions::X/ }
end

context "when referencing undefined methods" do
skip_natural_assertions_if_not_supported
Given(:failing_test) { "undefined_method_spec.rb" }
Then { ios.err == "" }
And { ios.out =~ /undefined local variable or method `xyz'/ }
And { complains_xyz_is_not_in_scope?(ios.out) }

def complains_xyz_is_not_in_scope?(out)
[
# RSpec <3.2's message:
"undefined local variable or method `xyz'",
# RSpec >3.2's message:
"`xyz` is not available from within an example"
].any? { |msg| out.include?(msg) }
end
end

context "when breaking down expressions" do
skip_natural_assertions_if_not_supported
Given(:failing_test) { "eval_subexpression_spec.rb" }
Then { ios.err == "" }
And { ios.out =~ /false *<- array\[index\]\.upcase == value$/ }
Expand All @@ -42,8 +56,9 @@ def run_spec(filename)
end

context "with an oddly formatted then" do
skip_natural_assertions_if_not_supported
Given(:failing_test) { "oddly_formatted_then.rb" }
Then { ios.out =~ /Failure\/Error: Then \{ result == \['a',$/ }
Then { ios.out =~ /Failure\/Error:\s*Then \{ result == \['a',$/ }
And { ios.out =~ /expected: "anything"/ }
And { ios.out =~ /to equal: \["a", "a"\]/ }
end
Expand Down
4 changes: 2 additions & 2 deletions examples/integration/given_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
end

context "when not called" do
Given(:value) { :ok }
Then { given_assert_equal :ok, value }
Given(:some_value) { :ok }
Then { given_assert_equal :ok, some_value }
end
end

Expand Down
3 changes: 1 addition & 2 deletions examples/integration/then_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ def to_bool

describe "Then" do
context "empty thens with natural assertions" do
use_natural_assertions_if_supported
skip_natural_assertions_if_not_supported #<--we can't detect void statements
Then { }
end
context "thens to_bool/true will pass" do
use_natural_assertions_if_supported
Then { ToBool.new(true) }
end
end
33 changes: 33 additions & 0 deletions examples/minitest-rails/test_case_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'minitest/autorun'
require 'active_support_helper'
require 'minitest/given'
require 'example_helper'


describe ActiveSupport::TestCase, :model do
Given(:info) { [] }
Given { info << "outer1" }
Given { info << "outer2" }

context "using a when without result" do
When { info << "when" }

context "inner with When" do
Given { info << "inner1" }
Given { info << "inner2" }
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when"], info }

context "using a nested When" do
When { info << "when2" }
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2"], info}
end

context "using two nested When" do
When { info << "when2a" }
When { info << "when2b" }
Then { given_assert_equal ["outer1", "outer2", "inner1", "inner2", "when", "when2a", "when2b"], info }
end
end
end
end

12 changes: 4 additions & 8 deletions examples/minitest_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module GivenAssertions
def given_assert(cond)
assert cond
Expand All @@ -23,16 +22,13 @@ def given_assert_raises(error, pattern=//, &block)
end

module NaturalAssertionControl
def use_natural_assertions_if_supported(enabled=true)
if enabled && ! Given::NATURAL_ASSERTIONS_SUPPORTED
Given {
skip "Natural assertions are not supported in JRuby"
}
else
use_natural_assertions(enabled)
def skip_natural_assertions_if_not_supported
if !Given::NATURAL_ASSERTIONS_SUPPORTED
Given { skip "This test requires a Ruby runtime with full natural assertions support." }
end
end
end

Minitest::Spec.send(:include, GivenAssertions)
Minitest::Test.send(:include, GivenAssertions)
include NaturalAssertionControl
Loading