spec/spec/example/example_group_spec.rb in rspec-1.1.12 vs spec/spec/example/example_group_spec.rb in rspec-1.2.0
- old
+ new
@@ -5,34 +5,44 @@
class ExampleModuleScopingSpec < ExampleGroup
describe ExampleGroup, "via a class definition"
module Foo
module Bar
- def self.loaded?
- true
- end
+ def self.loaded?; true; end
end
end
include Foo
it "should understand module scoping" do
Bar.should be_loaded
end
- @@foo = 1
+ @@class_variable = "a class variable"
- it "should allow class variables to be defined" do
- @@foo.should == 1
+ it "can access class variables in examples in Ruby 1.8" do
+ with_ruby 1.8 do
+ @@class_variable.should == "a class variable"
+ end
end
+
+ it "can NOT access class variables in examples in Ruby 1.9" do
+ with_ruby 1.9 do
+ lambda do
+ @@class_variable.should == "a class variable"
+ end.should raise_error(NameError)
+ end
+ end
+
+
end
class ExampleClassVariablePollutionSpec < ExampleGroup
describe ExampleGroup, "via a class definition without a class variable"
it "should not retain class variables from other Example classes" do
proc do
- @@foo
+ @@class_variable
end.should raise_error
end
end
describe ExampleGroup, "#pending" do
@@ -72,11 +82,11 @@
@formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
options.formatters << formatter
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
@reporter = FakeReporter.new(options)
options.reporter = reporter
- @example_group = Class.new(ExampleGroup) do
+ @example_group = Class.new(ExampleGroupDouble) do
describe("example")
it "does nothing" do
end
end
class << example_group
@@ -87,11 +97,11 @@
after :each do
ExampleGroup.reset
end
it "should not run when there are no examples" do
- example_group = Class.new(ExampleGroup) do
+ example_group = Class.new(ExampleGroupDouble) do
describe("Foobar")
end
example_group.examples.should be_empty
reporter = mock("Reporter")
@@ -162,11 +172,11 @@
end
describe "when specified_examples matches entire ExampleGroup" do
before do
examples_that_were_run = @examples_that_were_run
- @example_group = Class.new(ExampleGroup) do
+ @example_group = Class.new(ExampleGroupDouble) do
describe("the ExampleGroup")
it("should be run") do
examples_that_were_run << 'should be run'
end
@@ -184,11 +194,11 @@
end
describe ExampleGroup, "#run when specified_examples matches only Example description" do
before do
examples_that_were_run = @examples_that_were_run
- @example_group = Class.new(ExampleGroup) do
+ @example_group = Class.new(ExampleGroupDouble) do
describe("example")
it("should be run") do
examples_that_were_run << 'should be run'
end
end
@@ -202,11 +212,11 @@
end
describe ExampleGroup, "#run when specified_examples does not match an Example description" do
before do
examples_that_were_run = @examples_that_were_run
- @example_group = Class.new(ExampleGroup) do
+ @example_group = Class.new(ExampleGroupDouble) do
describe("example")
it("should be something else") do
examples_that_were_run << 'should be something else'
end
end
@@ -220,11 +230,11 @@
end
describe ExampleGroup, "#run when specified_examples matches an Example description" do
before do
examples_that_were_run = @examples_that_were_run
- @example_group = Class.new(ExampleGroup) do
+ @example_group = Class.new(ExampleGroupDouble) do
describe("example")
it("should be run") do
examples_that_were_run << 'should be run'
end
it("should not be run") do
@@ -232,26 +242,22 @@
end
end
options.parse_example "should be run"
end
- it "should run only the example, when there is only one" do
+ it "should run only the example" do
example_group.run(options)
examples_that_were_run.should == ["should be run"]
end
-
- it "should run only the one example" do
- example_group.run(options)
- examples_that_were_run.should == ["should be run"] end
end
end
describe ExampleGroup, "#run with success" do
before do
- @special_example_group = Class.new(ExampleGroup)
+ @special_example_group = Class.new(ExampleGroupDouble)
ExampleGroupFactory.register(:special, @special_example_group)
- @not_special_example_group = Class.new(ExampleGroup)
+ @not_special_example_group = Class.new(ExampleGroupDouble)
ExampleGroupFactory.register(:not_special, @not_special_example_group)
end
after do
ExampleGroupFactory.reset
@@ -315,11 +321,11 @@
@special_example_group.before(:each) { fiddle << "Example.before(:each, :type => :special)" }
@special_example_group.prepend_before(:each) { fiddle << "Example.prepend_before(:each, :type => :special)" }
@special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
@special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
- example_group = Class.new(ExampleGroup) do
+ example_group = Class.new(ExampleGroupDouble) do
describe("I'm not special", :type => :not_special)
it "does nothing"
end
example_group.run(options)
fiddle.should == [
@@ -432,51 +438,10 @@
example_group.included_modules.should include(mod1)
example_group.included_modules.should include(mod2)
example_group.included_modules.should_not include(mod3)
end
- it "should include any predicate_matchers included using configuration" do
- $included_predicate_matcher_found = false
- Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
- example_group = Class.new(ExampleGroup) do
- describe('example')
- it "should respond to do_something" do
- $included_predicate_matcher_found = respond_to?(:do_something)
- end
- end
- example_group.run(options)
- $included_predicate_matcher_found.should be(true)
- end
-
- it "should use a mock framework set up in config" do
- mod = Module.new do
- def self.included(mod)
- $included_module = mod
- end
-
- def teardown_mocks_for_rspec
- $torn_down = true
- end
- end
-
- begin
- $included_module = nil
- $torn_down = true
- Spec::Runner.configuration.mock_with mod
-
- example_group = Class.new(ExampleGroup) do
- describe('example')
- it "does nothing"
- end
- example_group.run(options)
-
- $included_module.should_not be_nil
- $torn_down.should == true
- ensure
- Spec::Runner.configuration.mock_with :rspec
- end
- end
end
describe ExampleGroup, "#run with pending example that has a failing assertion" do
before do
example_group.it("should be pending") do
@@ -532,11 +497,11 @@
example_group.run(options)
after_all_ran.should be_true
end
it "should supply before(:all) as description" do
- @reporter.should_receive(:failure) do |example, error|
+ @reporter.should_receive(:example_failed) do |example, error|
example.description.should eql("before(:all)")
error.message.should eql("before(:all) failure")
end
example_group.it("test") {true}
@@ -645,31 +610,19 @@
end
end
end
end
- class ExampleSubclass < ExampleGroup
- end
-
describe ExampleGroup, "subclasses" do
- after do
- ExampleGroupFactory.reset
- end
-
it "should have access to the described_type" do
- example_group = Class.new(ExampleSubclass) do
- describe(Array)
- end
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
example_group.__send__(:described_type).should == Array
end
it "should concat descriptions when nested" do
- example_group = Class.new(ExampleSubclass) do
- describe(Array)
- $nested_group = describe("when empty") do
- end
- end
- $nested_group.description.to_s.should == "Array when empty"
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
+ nested_group = example_group.describe("when empty") do; end
+ nested_group.description.to_s.should == "Array when empty"
end
end
end
end