Skip to content

Commit

Permalink
Multiple-gems for minitest/rspec/core.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Jul 9, 2013
1 parent a9ffa0d commit d8568a7
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 70 deletions.
6 changes: 3 additions & 3 deletions Gemfile
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

gem 'rake'
gem 'rspec'
gem 'minitest', '~> 5.0'
gem 'rspec', '>= 2.12'
gem 'minitest', '>= 4.3'
gem 'sorcerer', '>= 0.3.7'
gem 'flexmock'
gem 'flexmock'
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@
| :----: |
| [![Master Build Status](https://secure.travis-ci.org/jimweirich/rspec-given.png?branch=master)](https://travis-ci.org/jimweirich/rspec-given) |

Covering rspec-given, version 2.4.4.
Covering rspec-given, version 3.0.0.beta.1.

rspec-given is an RSpec extension to allow Given/When/Then notation in
RSpec specifications. It is a natural extension of the experimental
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -121,7 +121,7 @@ task :readme => ["README.md"] do
end

desc "Generate an RDoc README"
file "README.md" => ["examples/stack/stack_spec.rb", "lib/rspec/given/version.rb"] do
file "README.md" => ["examples/stack/stack_spec.rb", "lib/given/version.rb"] do
open("README.md") do |ins|
open("README.tmp", "w") do |outs|
state = :copy
Expand Down
4 changes: 2 additions & 2 deletions TODO
Expand Up @@ -2,12 +2,12 @@ Things to do to improve the minitest integration

TODO:

* General cleanup making sure files go where they need.
* Make a separate gem for minitest (do we need one for given-core?)
* Handle have_failed in minitest

DONE:

* Handle have_failed in minitest
* General cleanup making sure files go where they need.
* Implement assertion counting for minitest
* Figure out why the minitest example count is so low.
* Move stuff out of minitest_helper to appropriate file.
11 changes: 3 additions & 8 deletions lib/given/extensions.rb
Expand Up @@ -38,17 +38,12 @@ def _gvn_info(keyword) # :nodoc:
# Should a natural assertion failure message be generated?
#
# A natural assertion failure message is generated if the
# assertion has non-empty content that doesn't use the framework's
# assertions. The configuration options for natural assertions are
# checked and applied accordingly.
# assertion has non-empty content. The configuration options for
# natural assertions are checked and applied accordingly.
#
def _gvn_need_na_message?(nassert) # :nodoc:
return false unless nassert.has_content?
use_na = _gvn_na_configured?
return true if use_na == :always
# FIX: to make multi-framework
# return false if !RSpec::Given::MONKEY && nassert.using_rspec_assertion?
use_na
_gvn_na_configured?
end

# Return the configuration value for natural assertions.
Expand Down
12 changes: 0 additions & 12 deletions lib/given/natural_assertion.rb
Expand Up @@ -21,10 +21,6 @@ def initialize(clause_type, block, example, line_extractor)

VOID_SEXP = [:void_stmt]

def using_rspec_assertion?
using_should? || using_expect?
end

def has_content?
assertion_sexp != VOID_SEXP
end
Expand All @@ -40,14 +36,6 @@ def message

private

def using_should?
source =~ /\.\s*should(_not)?\b/
end

def using_expect?
source =~ /\bexpect\s*[({].*[)}]\s*\.\s*(not_)?to\b/
end

BINARY_EXPLAINATIONS = {
:== => "to equal",
:!= => "to not equal",
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/given.rb
Expand Up @@ -8,6 +8,7 @@ module Given

if Given::NATURAL_ASSERTIONS_SUPPORTED
require 'rspec/given/monkey'
raise "Unsupported version of RSpec (unable to detect assertions)" unless RSpec::Given::MONKEY
end

require 'rspec/given/have_failed'
Expand Down
117 changes: 106 additions & 11 deletions rakelib/gemspec.rake
Expand Up @@ -8,33 +8,97 @@ else
'[A-Z]*',
'lib/*.rb',
'lib/**/*.rb',
'rakelib/**/*',
'test/**/*.rb',
'spec/**/*.rb',
'examples/**/*',
'doc/**/*',
]
PKG_FILES.exclude('TAGS')
GIVEN_CORE_FILES = FileList[*PKG_FILES].
exclude("lib/minitest/**/*").
exclude("lib/rspec/**/*").
exclude("spec/**/*").
exclude("examples/**/*")
RSPEC_GIVEN_FILES = FileList[*PKG_FILES].
exclude("lib/minitest/**/*").
exclude("lib/given/**/*")
MINITEST_GIVEN_FILES = FileList[*PKG_FILES].
exclude("lib/rspec/**/*").
exclude("lib/given/**/*")

SPEC = Gem::Specification.new do |s|

#### Basic information.

RSPEC_GIVEN_SPEC = Gem::Specification.new do |s|
s.name = 'rspec-given'
s.version = Given::VERSION
s.summary = "Given/When/Then Specification Extensions for RSpec."
s.description = <<EOF
Given is an RSpec extension that allows the use of Given/When/Then
terminology when defining specifications.
EOF
s.files = PKG_FILES.to_a
s.files = RSPEC_GIVEN_FILES.to_a
s.require_path = 'lib' # Use these for libraries.
s.rdoc_options = [
'--line-numbers', '--inline-source',
'--main' , 'doc/main.rdoc',
'--title', 'RSpec Given Extensions'
]

s.add_dependency("given-core", "= #{Given::VERSION}")
s.add_dependency("rspec", ">= 2.12")

s.required_ruby_version = '>= 1.9.2'
s.license = "MIT"

s.author = "Jim Weirich"
s.email = "jim.weirich@gmail.com"
s.homepage = "http://github.com/jimweirich/rspec-given"
s.rubyforge_project = "given"
end

MINITEST_GIVEN_SPEC = Gem::Specification.new do |s|
s.name = 'minitest-given'
s.version = Given::VERSION
s.summary = "Given/When/Then Specification Extensions for MiniTest::Spec."
s.description = <<EOF
Given is a Minitest::Spec extension that allows the use of Given/When/Then
terminology when defining specifications.
EOF
s.files = MINITEST_GIVEN_FILES.to_a
s.require_path = 'lib' # Use these for libraries.
s.rdoc_options = [
'--line-numbers', '--inline-source',
'--main' , 'doc/main.rdoc',
'--title', 'Minitest Given Extensions'
]

s.add_dependency("given-core", "= #{Given::VERSION}")
s.add_dependency("minitest", "> 4.3")

s.required_ruby_version = '>= 1.9.2'
s.license = "MIT"

s.author = "Jim Weirich"
s.email = "jim.weirich@gmail.com"
s.homepage = "http://github.com/jimweirich/rspec-given"
s.rubyforge_project = "given"
end

GIVEN_CORE_SPEC = Gem::Specification.new do |s|
s.name = 'given-core'
s.version = Given::VERSION
s.summary = "Core engine for RSpec::Given and Minitest::Given."
s.description = <<EOF
Given is an RSpec/Minitest extension that allows the use of Given/When/Then
terminology when defining specifications.
EOF
s.files = GIVEN_CORE_FILES.to_a
s.require_path = 'lib' # Use these for libraries.
s.rdoc_options = [
'--line-numbers', '--inline-source',
'--main' , 'doc/main.rdoc',
'--title', 'RSpec Given Extensions'
]

s.add_dependency("minitest", "~> 5.0")
s.add_dependency("sorcerer", ">= 0.3.7")

s.required_ruby_version = '>= 1.9.2'
Expand All @@ -46,16 +110,47 @@ EOF
s.rubyforge_project = "given"
end

package_task = Gem::PackageTask.new(SPEC) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
Gem::PackageTask.new(MINITEST_GIVEN_SPEC) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end

Gem::PackageTask.new(RSPEC_GIVEN_SPEC) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end

Gem::PackageTask.new(GIVEN_CORE_SPEC) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end

file "rspec-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
require 'yaml'
open(t.name, "w") { |f| f.puts SPEC.to_yaml }
open(t.name, "w") { |f| f.puts RSPEC_GIVEN_SPEC.to_yaml }
end

file "minitest-given.gemspec" => ["rakelib/gemspec.rake"] do |t|
require 'yaml'
open(t.name, "w") { |f| f.puts MINITEST_GIVEN_SPEC.to_yaml }
end

file "given-core.gemspec" => ["rakelib/gemspec.rake"] do |t|
require 'yaml'
open(t.name, "w") { |f| f.puts GIVEN_CORE_SPEC.to_yaml }
end

desc "Create a stand-alone gemspec"
task :gemspec => "rspec-given.gemspec"
task :gemspec => ["rspec-given.gemspec", "minitest-given.gemspec", "given-core.gemspec"]

desc "Check Filelists"
task :filelists do
puts "==============="
puts "GIVEN_CORE_FILES=#{GIVEN_CORE_FILES.inspect}"
puts "==============="
puts "RSPEC_GIVEN_FILES=#{RSPEC_GIVEN_FILES.inspect}"
puts "==============="
puts "MINITEST_GIVEN_FILES=#{MINITEST_GIVEN_FILES.inspect}"
puts "==============="
end
end
32 changes: 0 additions & 32 deletions spec/lib/given/natural_assertion_spec.rb
Expand Up @@ -17,38 +17,6 @@
end
end

describe "detecting RSpec Assertions" do
context "with should" do
FauxThen { a.should == 1 }
Then { na.should be_using_rspec_assertion }
end

context "with should_not" do
FauxThen { a.should_not == 1 }
Then { na.should be_using_rspec_assertion }
end

context "with expect/to" do
FauxThen { expect(a).to eq(1) }
Then { na.should be_using_rspec_assertion }
end

context "with expect/not_to" do
FauxThen { expect(a).not_to eq(1) }
Then { na.should be_using_rspec_assertion }
end

context "with expect and block" do
FauxThen { expect { a }.to eq(1) }
Then { na.should be_using_rspec_assertion }
end

context "with natural assertion" do
FauxThen { a == 1 }
Then { na.should_not be_using_rspec_assertion }
end
end

describe "failure messages" do
let(:msg) { na.message }
Invariant { msg.should =~ /^FauxThen expression/ }
Expand Down

0 comments on commit d8568a7

Please sign in to comment.