Permalink
Browse files

Swap out Rspec::Core.world instead of invading ExampleGroup

  • Loading branch information...
dchelimsky committed Apr 24, 2010
1 parent 6c425ed commit 35e4a6b037b992d5fa88784687bac780d360917d
@@ -99,8 +99,6 @@ def self.file_path
end
def self.describe(*args, &example_group_block)
- raise(ArgumentError, "No arguments given. You must a least supply a type or description") if args.empty?
- raise(ArgumentError, "You must supply a block when calling describe") if example_group_block.nil?
@_subclass_count ||= 0
@_subclass_count += 1
args << {} unless args.last.is_a?(Hash)
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
- s.date = %q{2010-04-17}
+ s.date = %q{2010-04-24}
s.description = %q{Rspec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.executables = ["rspec", "spec"]
@@ -105,6 +105,7 @@ Gem::Specification.new do |s|
"lib/rspec/core/configuration.rb",
"lib/rspec/core/configuration_options.rb",
"lib/rspec/core/deprecation.rb",
+ "lib/rspec/core/errors.rb",
"lib/rspec/core/example.rb",
"lib/rspec/core/example_group.rb",
"lib/rspec/core/formatters.rb",
@@ -136,7 +136,7 @@ def you_call_this_a_blt?
it "includes the given module into each example group" do
config.include(InstanceLevelMethods)
- group = ExampleGroup.create(config, 'does like, stuff and junk', :magic_key => :include) { }
+ group = ExampleGroup.describe(config, 'does like, stuff and junk', :magic_key => :include) { }
group.should_not respond_to(:you_call_this_a_blt?)
group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
end
@@ -147,7 +147,7 @@ def you_call_this_a_blt?
it "includes the given module into each matching example group" do
config.include(InstanceLevelMethods, :magic_key => :include)
- group = ExampleGroup.create(config, 'does like, stuff and junk', :magic_key => :include) { }
+ group = ExampleGroup.describe(config, 'does like, stuff and junk', :magic_key => :include) { }
group.should_not respond_to(:you_call_this_a_blt?)
group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
end
@@ -164,7 +164,7 @@ def that_thing
it "should extend the given module into each matching example group" do
config.extend(ThatThingISentYou, :magic_key => :extend)
- group = ExampleGroup.create(config, ThatThingISentYou, :magic_key => :extend) { }
+ group = ExampleGroup.describe(config, ThatThingISentYou, :magic_key => :extend) { }
group.should respond_to(:that_thing)
end
@@ -14,33 +14,20 @@ module Rspec::Core
describe ExampleGroup do
- describe "#describe" do
-
- it "raises an ArgumentError if no type or description is given" do
- lambda { ExampleGroup.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
- end
-
- it "raises an ArgumentError if no block is given" do
- lambda { ExampleGroup.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
- end
-
- end
-
-
describe '#describes' do
context "with a constant as the first parameter" do
it "is that constant" do
- ExampleGroup.create(Object) { }.describes.should == Object
+ ExampleGroup.describe(Object) { }.describes.should == Object
end
end
context "with a string as the first parameter" do
it "is nil" do
- ExampleGroup.create("i'm a computer") { }.describes.should be_nil
+ ExampleGroup.describe("i'm a computer") { }.describes.should be_nil
end
end
@@ -50,7 +37,7 @@ module Rspec::Core
describe '#description' do
it "grabs the description from the metadata" do
- group = ExampleGroup.create(Object, "my desc") { }
+ group = ExampleGroup.describe(Object, "my desc") { }
group.description.should == group.metadata[:example_group][:description]
end
@@ -59,39 +46,39 @@ module Rspec::Core
describe '#metadata' do
it "adds the third parameter to the metadata" do
- ExampleGroup.create(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
+ ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
end
it "adds the caller to metadata" do
- ExampleGroup.create(Object) { }.metadata[:example_group][:caller].any? {|f|
+ ExampleGroup.describe(Object) { }.metadata[:example_group][:caller].any? {|f|
f =~ /#{__FILE__}/
}.should be_true
end
it "adds the the file_path to metadata" do
- ExampleGroup.create(Object) { }.metadata[:example_group][:file_path].should == __FILE__
+ ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should == __FILE__
end
it "has a reader for file_path" do
- ExampleGroup.create(Object) { }.file_path.should == __FILE__
+ ExampleGroup.describe(Object) { }.file_path.should == __FILE__
end
it "adds the line_number to metadata" do
- ExampleGroup.create(Object) { }.metadata[:example_group][:line_number].should == __LINE__
+ ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
end
end
describe "before, after, and around hooks" do
it "exposes the before each blocks at before_eachs" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.before(:each) { 'foo' }
group.should have(1).before_eachs
end
it "maintains the before each block order" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.before(:each) { 15 }
group.before(:each) { 'A' }
group.before(:each) { 33.5 }
@@ -102,13 +89,13 @@ module Rspec::Core
end
it "exposes the before all blocks at before_alls" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.before(:all) { 'foo' }
group.should have(1).before_alls
end
it "maintains the before all block order" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.before(:all) { 15 }
group.before(:all) { 'A' }
group.before(:all) { 33.5 }
@@ -119,13 +106,13 @@ module Rspec::Core
end
it "exposes the after each blocks at after_eachs" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.after(:each) { 'foo' }
group.should have(1).after_eachs
end
it "maintains the after each block order" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.after(:each) { 15 }
group.after(:each) { 'A' }
group.after(:each) { 33.5 }
@@ -136,13 +123,13 @@ module Rspec::Core
end
it "exposes the after all blocks at after_alls" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.after(:all) { 'foo' }
group.should have(1).after_alls
end
it "maintains the after each block order" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.after(:all) { 15 }
group.after(:all) { 'A' }
group.after(:all) { 33.5 }
@@ -153,7 +140,7 @@ module Rspec::Core
end
it "exposes the around each blocks at after_alls" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.around(:each) { 'foo' }
group.should have(1).around_eachs
end
@@ -163,21 +150,21 @@ module Rspec::Core
describe "adding examples" do
it "allows adding an example using 'it'" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.it("should do something") { }
group.examples.size.should == 1
end
it "exposes all examples at examples" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.it("should do something 1") { }
group.it("should do something 2") { }
group.it("should do something 3") { }
group.examples.size.should == 3
end
it "maintains the example order" do
- group = ExampleGroup.create
+ group = ExampleGroup.describe
group.it("should 1") { }
group.it("should 2") { }
group.it("should 3") { }
@@ -215,7 +202,7 @@ module Rspec::Core
let(:reporter) { double("reporter").as_null_object }
it "returns true if all examples pass" do
- group = ExampleGroup.create('group') do
+ group = ExampleGroup.describe('group') do
example('ex 1') { 1.should == 1 }
example('ex 2') { 1.should == 1 }
end
@@ -224,7 +211,7 @@ module Rspec::Core
end
it "returns false if any of the examples fail" do
- group = ExampleGroup.create('group') do
+ group = ExampleGroup.describe('group') do
example('ex 1') { 1.should == 1 }
example('ex 2') { 1.should == 2 }
end
@@ -233,7 +220,7 @@ module Rspec::Core
end
it "runs all examples, regardless of any of them failing" do
- group = ExampleGroup.create('group') do
+ group = ExampleGroup.describe('group') do
example('ex 1') { 1.should == 2 }
example('ex 2') { 1.should == 1 }
end
@@ -62,29 +62,29 @@
end
describe "#run" do
- it "should run after(:each) when the example passes" do
+ it "runs after(:each) when the example passes" do
after_run = false
- group = Rspec::Core::ExampleGroup.create do
+ group = Rspec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { 1.should == 1 }
end
group.run_all
after_run.should be_true, "expected after(:each) to be run"
end
- it "should run after(:each) when the example fails" do
+ it "runs after(:each) when the example fails" do
after_run = false
- group = Rspec::Core::ExampleGroup.create do
+ group = Rspec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { 1.should == 2 }
end
group.run_all
after_run.should be_true, "expected after(:each) to be run"
end
- it "should run after(:each) when the example raises an Exception" do
+ it "runs after(:each) when the example raises an Exception" do
after_run = false
- group = Rspec::Core::ExampleGroup.create do
+ group = Rspec::Core::ExampleGroup.describe do
after(:each) { after_run = true }
example('example') { raise "this error" }
end
@@ -10,7 +10,7 @@
use_formatter(formatter) do
- group = Rspec::Core::ExampleGroup.create("my favorite pony") do
+ group = Rspec::Core::ExampleGroup.describe("my favorite pony") do
example("showing a double fail") do
foo = "string"
foo.expects(:something)
@@ -13,7 +13,7 @@
describe "an example" do
context "with no block" do
it "is listed as pending with 'Not Yet Implemented'" do
- group = Rspec::Core::ExampleGroup.create('group') do
+ group = Rspec::Core::ExampleGroup.describe('group') do
it "has no block"
end
example = group.examples.first
@@ -24,7 +24,7 @@
context "with no args" do
it "is listed as pending with 'No reason given'" do
- group = Rspec::Core::ExampleGroup.create('group') do
+ group = Rspec::Core::ExampleGroup.describe('group') do
it "does something" do
pending
end
@@ -37,7 +37,7 @@
context "with a message" do
it "is listed as pending with the supplied message" do
- group = Rspec::Core::ExampleGroup.create('group') do
+ group = Rspec::Core::ExampleGroup.describe('group') do
it "does something" do
pending("just because")
end
@@ -51,7 +51,7 @@
context "with a block" do
context "that fails" do
it "is listed as pending with the supplied message" do
- group = Rspec::Core::ExampleGroup.create('group') do
+ group = Rspec::Core::ExampleGroup.describe('group') do
it "does something" do
pending("just because") do
3.should == 4
@@ -66,7 +66,7 @@
context "that passes" do
it "raises a PendingExampleFixedError" do
- group = Rspec::Core::ExampleGroup.create('group') do
+ group = Rspec::Core::ExampleGroup.describe('group') do
it "does something" do
pending("just because") do
3.should == 3
Oops, something went wrong.

0 comments on commit 35e4a6b

Please sign in to comment.