Skip to content
Browse files

Updated to work with RSpec 2.0.0.beta.20

  • Loading branch information...
1 parent f12f19f commit b3542487fe9834d2655d8209aab6314a47dc0fd6 @glv committed Sep 5, 2010
Showing with 136 additions and 135 deletions.
  1. +1 −1 Gemfile
  2. +30 −39 Gemfile.lock
  3. +4 −19 Rakefile
  4. +1 −1 lib/rspec/unit/assertions.rb
  5. +20 −12 lib/rspec/unit/test_case.rb
  6. +23 −20 rspec-unit.gemspec
  7. +2 −2 spec/assertions_spec.rb
  8. +28 −19 spec/spec_helper.rb
  9. +27 −22 spec/test_case_spec.rb
View
2 Gemfile
@@ -1,7 +1,7 @@
source :gemcutter
# gem 'bundler', '>= 0.9.16'
-gem 'rspec', '>= 2.0.0.beta.5'
+gem 'rspec', '= 2.0.0.beta.20'
group :test do
gem 'rake', '>= 0.8.7'
View
69 Gemfile.lock
@@ -1,39 +1,30 @@
----
-dependencies:
- rake:
- group:
- - :test
- version: ">= 0.8.7"
- rspec:
- group:
- - :default
- version: ">= 2.0.0.beta.5"
- jeweler:
- group:
- - :release
- version: ">= 1.4.0"
-specs:
-- rake:
- version: 0.8.7
-- json_pure:
- version: 1.2.3
-- gemcutter:
- version: 0.5.0
-- git:
- version: 1.2.5
-- rubyforge:
- version: 2.0.4
-- jeweler:
- version: 1.4.0
-- rspec-core:
- version: 2.0.0.beta.5
-- rspec-expectations:
- version: 2.0.0.beta.5
-- rspec-mocks:
- version: 2.0.0.beta.5
-- rspec:
- version: 2.0.0.beta.5
-hash: 810abde8fee4cc8af22ca62810a28b4f24fded08
-sources:
-- Rubygems:
- uri: http://gemcutter.org
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.2)
+ gemcutter (0.6.1)
+ git (1.2.5)
+ jeweler (1.4.0)
+ gemcutter (>= 0.1.0)
+ git (>= 1.2.5)
+ rubyforge (>= 2.0.0)
+ json_pure (1.4.6)
+ rake (0.8.7)
+ rspec (2.0.0.beta.20)
+ rspec-core (= 2.0.0.beta.20)
+ rspec-expectations (= 2.0.0.beta.20)
+ rspec-mocks (= 2.0.0.beta.20)
+ rspec-core (2.0.0.beta.20)
+ rspec-expectations (2.0.0.beta.20)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.20)
+ rubyforge (2.0.4)
+ json_pure (>= 1.1.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jeweler (>= 1.4.0)
+ rake (>= 0.8.7)
+ rspec (= 2.0.0.beta.20)
View
23 Rakefile
@@ -1,19 +1,4 @@
-def rcr?
- ENV['RUN_CODE_RUN'] == 'true'
-end
-
-system("bundle check || bundle install --disable-shared-gems")
-
-begin
- # Try to require the preresolved locked set of gems.
- require File.expand_path('../.bundle/environment', __FILE__)
-rescue LoadError
- # Fall back on doing an unlocked resolve at runtime.
- puts "Something's wrong with bundle configuration. Falling back to RubyGems."
- require "rubygems"
- require "bundler"
- Bundler.setup
-end
+require 'bundler/setup'
begin
require 'jeweler'
@@ -24,7 +9,7 @@ begin
gem.homepage = "http://github.com/glv/rspec-unit"
gem.authors = ["Glenn Vanderburg"]
gem.rubyforge_project = "rspec-unit"
- gem.add_dependency('rspec', '>= 2.0.0.a7')
+ gem.add_dependency('rspec', '>= 2.0.0.beta.5')
gem.has_rdoc = false
gem.files = FileList["[A-Z]*", "{bin,lib,examples}/**/*"]
gem.rubyforge_project = 'glv'
@@ -37,12 +22,12 @@ rescue LoadError
end
require 'rspec/core/rake_task'
-Rspec::Core::RakeTask.new(:examples) do |examples|
+RSpec::Core::RakeTask.new(:examples) do |examples|
examples.pattern = 'spec/**/*_spec.rb'
examples.ruby_opts = '-Ilib -Ispec'
end
-Rspec::Core::RakeTask.new(:rcov) do |examples|
+RSpec::Core::RakeTask.new(:rcov) do |examples|
examples.pattern = 'spec/**/*_spec.rb'
examples.rcov_opts = '-Ilib -Ispec -x "/Library/Ruby/Gems,^spec/"'
examples.rcov = true
View
2 lib/rspec/unit/assertions.rb
@@ -2,7 +2,7 @@
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
-module Rspec
+module RSpec
module Unit
##
View
32 lib/rspec/unit/test_case.rb
@@ -1,10 +1,10 @@
require 'rspec/unit/assertions'
-module Rspec
+module RSpec
module Core
class ExampleGroup
- include ::Rspec::Unit::Assertions
+ include ::RSpec::Unit::Assertions
end
class <<Runner
@@ -14,25 +14,27 @@ def installed_at_exit?; true; end
end
module Unit
- class AssertionFailedError < Rspec::Matchers::MatcherError
+ class AssertionFailedError < RSpec::Matchers::MatcherError
end
- class TestCase < Rspec::Core::ExampleGroup
+ class TestCase < RSpec::Core::ExampleGroup
TEST_METHOD_PATTERN = /^test_/
alias_example_to :test, :test_unit => true
- @configuration = Rspec.configuration
+ @configuration = RSpec.configuration
def self.inherited(klass)
super
install_setup_and_teardown(klass)
name = test_case_name(klass)
- _build(klass, caller, [name, {}])
+ klass.set_it_up(name, {:caller => caller})
klass.metadata[:example_group][:test_unit] = true
+ children << klass
+ world.example_groups << klass
end
def self.test_case_info(options)
@@ -56,12 +58,12 @@ def self.examples
@tc_examples ||= ExamplesCollection.new(self, super)
end
- def self.ancestors(superclass_last=false)
- superclass_last ? super[0..-2] : super[1..-1]
+ def self.ancestors
+ super[0..-2]
end
def self.to_s
- self == Rspec::Unit::TestCase ? 'Rspec::Unit::TestCase' : super
+ self == RSpec::Unit::TestCase ? 'RSpec::Unit::TestCase' : super
end
def self.test_case_name(klass)
@@ -80,7 +82,7 @@ def self.test_method_metadata
def self.install_setup_and_teardown(klass)
# Only do this for direct descendants, because test/unit chains
# fixtures through explicit calls to super.
- if self == Rspec::Unit::TestCase
+ if self == RSpec::Unit::TestCase
klass.class_eval do
before {setup}
after {teardown}
@@ -169,8 +171,8 @@ def empty?
core_examples.empty? && number_of_tests == 0
end
- def first
- core_examples.first || tests.first
+ def last
+ tests.last || core_examples.last
end
def <<(example)
@@ -185,9 +187,15 @@ def each
def to_ary
core_examples + tests
end
+
+ def uniq
+ to_ary.uniq
+ end
end
end
+
+ RSpec.world.example_groups.delete(::RSpec::Unit::TestCase)
end
module Core
View
43 rspec-unit.gemspec
@@ -1,52 +1,55 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{micronaut-unit}
- s.version = "0.2.0"
+ s.name = %q{rspec-unit}
+ s.version = "0.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Glenn Vanderburg"]
- s.date = %q{2009-05-23}
+ s.date = %q{2010-04-04}
s.email = %q{glv@vanderburg.org}
s.extra_rdoc_files = [
- "LICENSE",
+ "LICENSE",
"README.md"
]
s.files = [
+ "Gemfile",
+ "Gemfile.lock",
"LICENSE",
"README.md",
"Rakefile",
"VERSION.yml",
- "examples/assertions_example.rb",
- "examples/example_helper.rb",
- "examples/test_case_example.rb",
- "lib/micronaut-unit.rb",
- "lib/micronaut/unit.rb",
- "lib/micronaut/unit/assertions.rb",
- "lib/micronaut/unit/test_case.rb"
+ "lib/rspec-unit.rb",
+ "lib/rspec/unit.rb",
+ "lib/rspec/unit/assertions.rb",
+ "lib/rspec/unit/test_case.rb"
]
- s.homepage = %q{http://github.com/glv/micronaut-unit}
+ s.homepage = %q{http://github.com/glv/rspec-unit}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{glv}
- s.rubygems_version = %q{1.3.3}
- s.summary = %q{Adds test/unit compatibility to Micronaut.}
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{Adds test/unit compatibility to Rspec.}
s.test_files = [
- "examples/assertions_example.rb",
- "examples/example_helper.rb",
- "examples/test_case_example.rb"
+ "spec/assertions_spec.rb",
+ "spec/spec_helper.rb",
+ "spec/test_case_spec.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<spicycode-micronaut>, [">= 0.2.9"])
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.5"])
else
- s.add_dependency(%q<spicycode-micronaut>, [">= 0.2.9"])
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.5"])
end
else
- s.add_dependency(%q<spicycode-micronaut>, [">= 0.2.9"])
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.5"])
end
end
+
View
4 spec/assertions_spec.rb
@@ -6,8 +6,8 @@
# This is borrowed with minor changes from test/unit. I'm leaving it in test/unit format
# rather than converting to rspec-style. ---glv
-class TC_Assertions < Rspec::Unit::TestCase
- AssertionFailedError = Rspec::Unit::AssertionFailedError
+class TC_Assertions < RSpec::Unit::TestCase
+ AssertionFailedError = RSpec::Unit::AssertionFailedError
def check(value, message="")
add_assertion
View
47 spec/spec_helper.rb
@@ -1,50 +1,59 @@
-begin
- # Try to require the preresolved locked set of gems.
- require File.expand_path('../../.bundle/environment', __FILE__)
-rescue LoadError
- # Fall back on doing an unlocked resolve at runtime.
- puts "Something's wrong with bundle configuration. Falling back to RubyGems."
- require "rubygems"
- require "bundler"
- Bundler.setup
-end
-
-require 'rspec'
+require 'rubygems'
+require 'bundler/setup'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rspec-unit'
def remove_last_describe_from_world
- Rspec::Core.world.example_groups.pop
+ RSpec.world.example_groups.pop
+end
+
+def sandboxed(&block)
+ begin
+ @orig_config = RSpec.configuration
+ @orig_world = RSpec.world
+ new_config = RSpec::Core::Configuration.new
+ new_world = RSpec::Core::World.new(new_config)
+ RSpec.instance_variable_set(:@configuration, new_config)
+ RSpec.instance_variable_set(:@world, new_world)
+ object = Object.new
+ object.extend(RSpec::Core::ObjectExtensions)
+ object.extend(RSpec::Core::SharedExampleGroup)
+
+ object.instance_eval(&block)
+ ensure
+ RSpec.instance_variable_set(:@configuration, @orig_config)
+ RSpec.instance_variable_set(:@world, @orig_world)
+ end
end
def isolate_example_group
if block_given?
yield
- Rspec::Core.world.example_groups.pop
+ RSpec.world.example_groups.pop
end
end
def use_formatter(new_formatter)
- original_formatter = Rspec.configuration.formatter
- Rspec.configuration.instance_variable_set(:@formatter, new_formatter)
+ original_formatter = RSpec.configuration.formatter
+ RSpec.configuration.instance_variable_set(:@formatter, new_formatter)
yield
ensure
- Rspec.configuration.instance_variable_set(:@formatter, original_formatter)
+ RSpec.configuration.instance_variable_set(:@formatter, original_formatter)
end
def in_editor?
ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
end
-Rspec.configure do |c|
+RSpec.configure do |c|
c.mock_framework = :rspec
c.filter_run :focused => true
c.run_all_when_everything_filtered = true
c.color_enabled = !in_editor?
c.alias_example_to :fit, :focused => true
c.profile_examples = false
- c.formatter = :documentation # if ENV["RUN_CODE_RUN"] == "true"
+ c.formatter = :documentation
end
View
49 spec/test_case_spec.rb
@@ -1,25 +1,24 @@
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
-describe Rspec::Core::ExampleGroup do
+describe RSpec::Core::ExampleGroup do
it "supports using assertions in examples" do
lambda {assert_equal 1, 1}.should_not raise_error
end
end
-describe Rspec::Unit::TestCase do
+describe "RSpec::Unit::TestCase" do
before do
- @foo = Class.new(Rspec::Unit::TestCase)
+ @foo = Class.new(RSpec::Unit::TestCase)
@foo_definition_line = __LINE__ - 1
@caller_at_foo_definition = caller
- @formatter = Rspec::Core::Formatters::BaseFormatter.new
+ @formatter = RSpec::Core::Formatters::BaseFormatter.new('')
end
after do
remove_last_describe_from_world
end
def run_tests(klass)
- klass.examples_to_run.replace(klass.examples)
klass.run(@formatter)
end
@@ -126,7 +125,7 @@ def test_baz; end
end
end
- it "records failed tests in Rspec style" do
+ it "records failed tests in RSpec style" do
use_formatter(@formatter) do
@foo.class_eval do
def test_bar; flunk; end
@@ -147,8 +146,8 @@ def teardown; self.class._passed = passed?; end
@foo._passed.should == false
end
end
-
- it "records passed tests in Rspec style" do
+
+ it "records passed tests in RSpec style" do
use_formatter(@formatter) do
@foo.class_eval do
def test_bar; assert true; end
@@ -171,27 +170,33 @@ def teardown; self.class._passed = passed?; end
end
end
+ describe "inherited" do
+ it "adds the new subclass to RSpec.world.example_groups" do
+ sandboxed do
+ class SampleTestCase < RSpec::Unit::TestCase
+ end
+ RSpec.world.example_groups.should == [SampleTestCase]
+ end
+ end
+ end
+
describe "ancestors" do
before do
@bar = Class.new(@foo)
remove_last_describe_from_world
end
- it "removes TestCase from the beginning if superclass_last is false" do
- @bar.ancestors.should == [@foo, @bar]
- end
-
- it "removes TestCase from the end if superclass_last is true" do
- @bar.ancestors(true).should == [@bar, @foo]
+ it "removes TestCase from the end" do
+ @bar.ancestors.should == [@bar, @foo]
end
end
-
+
describe "test class metadata" do
- isolate_example_group do
- class SampleTestCaseForName < Rspec::Unit::TestCase
+ sandboxed do
+ class SampleTestCaseForName < RSpec::Unit::TestCase
end
end
-
+
it "sets :description to 'TestCase' and the class name if the class has one" do
SampleTestCaseForName.metadata[:example_group][:description].should == "TestCase SampleTestCaseForName"
end
@@ -254,7 +259,7 @@ def test_baz; end
end
@foo.examples.first.metadata[:description].should == 'test_baz'
end
-
+
it "uses a test method's name with the class name as its :full_description" do
@foo.class_eval do
def test_baz; end
@@ -268,7 +273,7 @@ def test_baz; end
end
test_baz_metadata[:test_unit].should be_true
end
-
+
it "sets :file_path to the file where the method is defined" do
@foo.class_eval do
def test_baz; end
@@ -306,7 +311,7 @@ def test_baz; end
test_baz_metadata[:caller].first.should == @foo.examples.first.metadata[:location]
test_baz_metadata[:caller].size.should == caller.size + 3
end
-
+
it "records test_info options for next test method" do
@foo.class_eval do
test_info :foo => :bar
@@ -370,7 +375,7 @@ def test_bar; end
after {bar}
def test_bar; end
end
-
+
@foo.should_receive(:bar).once
run_tests(@foo)
end

0 comments on commit b354248

Please sign in to comment.
Something went wrong with that request. Please try again.