From olio-commits-return-28-apmail-incubator-olio-commits-archive=incubator.apache.org@incubator.apache.org Thu Dec 11 18:57:30 2008 Return-Path: Delivered-To: apmail-incubator-olio-commits-archive@locus.apache.org Received: (qmail 30352 invoked from network); 11 Dec 2008 01:35:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Dec 2008 01:35:50 -0000 Received: (qmail 34191 invoked by uid 500); 11 Dec 2008 01:36:03 -0000 Delivered-To: apmail-incubator-olio-commits-archive@incubator.apache.org Received: (qmail 34178 invoked by uid 500); 11 Dec 2008 01:36:03 -0000 Mailing-List: contact olio-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: olio-dev@incubator.apache.org Delivered-To: mailing list olio-commits@incubator.apache.org Received: (qmail 34166 invoked by uid 99); 11 Dec 2008 01:36:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Dec 2008 17:36:02 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Dec 2008 01:35:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 462762388A5D; Wed, 10 Dec 2008 17:34:47 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r725524 [11/14] - in /incubator/olio/webapp/rails/trunk: app/controllers/ app/models/ app/views/events/ config/ config/environments/ spec/controllers/ spec/models/ vendor/plugins/attachment_fu/ vendor/plugins/attachment_fu/lib/ vendor/plugi... Date: Thu, 11 Dec 2008 01:34:30 -0000 To: olio-commits@incubator.apache.org From: wsobel@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081211013447.462762388A5D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb Wed Dec 10 17:34:18 2008 @@ -65,584 +65,584 @@ end describe ExampleGroup, "#run" do - it_should_behave_like "sandboxed rspec_options" - attr_reader :example_group, :formatter, :reporter - before :each do - @formatter = mock("formatter", :null_object => true) - 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 - describe("example") - it "does nothing" do - end - end - class << example_group - public :include - end - end - - after :each do - ExampleGroup.reset - end - - it "should not run when there are no examples" do - example_group = Class.new(ExampleGroup) do - describe("Foobar") - end - example_group.examples.should be_empty - - reporter = mock("Reporter") - reporter.should_not_receive(:add_example_group) - example_group.run - end - - describe "when before_each fails" do - before(:each) do - $example_ran = $after_each_ran = false - @example_group = describe("Foobar") do - before(:each) {raise} - it "should not be run" do - $example_ran = true - end - after(:each) do - $after_each_ran = true + with_sandboxed_options do + attr_reader :example_group, :formatter, :reporter + before :each do + method_with_three_args = lambda { |arg1, arg2, arg3| } + @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 + describe("example") + it "does nothing" do end end - end - - it "should not run example block" do - example_group.run - $example_ran.should be_false - end - - it "should run after_each" do - example_group.run - $after_each_ran.should be_true - end - - it "should report failure location when in before_each" do - reporter.should_receive(:example_finished) do |example_group, error| - error.message.should eql("in before_each") + class << example_group + public :include end - example_group.run end - end - describe ExampleGroup, "#run on dry run" do - before do - @options.dry_run = true + after :each do + ExampleGroup.reset end - it "should not run before(:all) or after(:all)" do - before_all_ran = false - after_all_ran = false - ExampleGroup.before(:all) { before_all_ran = true } - ExampleGroup.after(:all) { after_all_ran = true } - example_group.it("should") {} - example_group.run - before_all_ran.should be_false - after_all_ran.should be_false - end + it "should not run when there are no examples" do + example_group = Class.new(ExampleGroup) do + describe("Foobar") + end + example_group.examples.should be_empty - it "should not run example" do - example_ran = false - example_group.it("should") {example_ran = true} + reporter = mock("Reporter") + reporter.should_not_receive(:add_example_group) example_group.run - example_ran.should be_false - end - end - - describe ExampleGroup, "#run with specified examples" do - attr_reader :examples_that_were_run - before do - @examples_that_were_run = [] 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 - describe("the ExampleGroup") - it("should be run") do - examples_that_were_run << 'should be run' + + describe "when before_each fails" do + before(:each) do + $example_ran = $after_each_ran = false + @example_group = describe("Foobar") do + before(:each) {raise} + it "should not be run" do + $example_ran = true end - - it("should also be run") do - examples_that_were_run << 'should also be run' + after(:each) do + $after_each_ran = true end end - options.examples = ["the ExampleGroup"] end - it "should not run the Examples in the ExampleGroup" do + it "should not run example block" do example_group.run - examples_that_were_run.should == ['should be run', 'should also be run'] + $example_ran.should be_false end - 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 - describe("example") - it("should be run") do - examples_that_were_run << 'should be run' - end - end - options.examples = ["should be run"] + + it "should run after_each" do + example_group.run + $after_each_ran.should be_true end - it "should not run the example" do + it "should report failure location when in before_each" do + reporter.should_receive(:example_finished) do |example_group, error| + error.message.should eql("in before_each") + end example_group.run - examples_that_were_run.should == ['should be run'] end end - describe ExampleGroup, "#run when specified_examples does not match an Example description" do + describe ExampleGroup, "#run on dry run" do before do - examples_that_were_run = @examples_that_were_run - @example_group = Class.new(ExampleGroup) do - describe("example") - it("should be something else") do - examples_that_were_run << 'should be something else' - end - end - options.examples = ["does not match anything"] + @options.dry_run = true end - it "should not run the example" do + it "should not run before(:all) or after(:all)" do + before_all_ran = false + after_all_ran = false + ExampleGroup.before(:all) { before_all_ran = true } + ExampleGroup.after(:all) { after_all_ran = true } + example_group.it("should") {} example_group.run - examples_that_were_run.should == [] + before_all_ran.should be_false + after_all_ran.should be_false + end + + it "should not run example" do + example_ran = false + example_group.it("should") {example_ran = true} + example_group.run + example_ran.should be_false end end - describe ExampleGroup, "#run when specified_examples matches an Example description" do + describe ExampleGroup, "#run with specified examples" do + attr_reader :examples_that_were_run before do - examples_that_were_run = @examples_that_were_run - @example_group = Class.new(ExampleGroup) do - describe("example") - it("should be run") do - examples_that_were_run << 'should be run' - end - it("should not be run") do - examples_that_were_run << 'should not be run' + @examples_that_were_run = [] + 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 + describe("the ExampleGroup") + it("should be run") do + examples_that_were_run << 'should be run' + end + + it("should also be run") do + examples_that_were_run << 'should also be run' + end end + options.examples = ["the ExampleGroup"] end - options.examples = ["should be run"] - end - it "should run only the example, when there in only one" do - example_group.run - examples_that_were_run.should == ["should be run"] + it "should not run the Examples in the ExampleGroup" do + example_group.run + examples_that_were_run.should == ['should be run', 'should also be run'] + end end - it "should run only the one example" do - example_group.run - examples_that_were_run.should == ["should be run"] end - end - 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 + describe("example") + it("should be run") do + examples_that_were_run << 'should be run' + end + end + options.examples = ["should be run"] + end - describe ExampleGroup, "#run with success" do - before do - @special_example_group = Class.new(ExampleGroup) - ExampleGroupFactory.register(:special, @special_example_group) - @not_special_example_group = Class.new(ExampleGroup) - ExampleGroupFactory.register(:not_special, @not_special_example_group) - end + it "should not run the example" do + example_group.run + examples_that_were_run.should == ['should be run'] + end + end - after do - ExampleGroupFactory.reset - 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 + describe("example") + it("should be something else") do + examples_that_were_run << 'should be something else' + end + end + options.examples = ["does not match anything"] + end - it "should send reporter add_example_group" do - example_group.run - reporter.example_groups.should == [example_group] - end + it "should not run the example" do + example_group.run + examples_that_were_run.should == [] + end + end - it "should run example on run" do - example_ran = false - example_group.it("should") {example_ran = true} - example_group.run - example_ran.should be_true - 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 + describe("example") + it("should be run") do + examples_that_were_run << 'should be run' + end + it("should not be run") do + examples_that_were_run << 'should not be run' + end + end + options.examples = ["should be run"] + end - it "should run before(:all) block only once" do - before_all_run_count_run_count = 0 - example_group.before(:all) {before_all_run_count_run_count += 1} - example_group.it("test") {true} - example_group.it("test2") {true} - example_group.run - before_all_run_count_run_count.should == 1 - end + it "should run only the example, when there is only one" do + example_group.run + examples_that_were_run.should == ["should be run"] + end - it "should run after(:all) block only once" do - after_all_run_count = 0 - example_group.after(:all) {after_all_run_count += 1} - example_group.it("test") {true} - example_group.it("test2") {true} - example_group.run - after_all_run_count.should == 1 - @reporter.rspec_verify + it "should run only the one example" do + example_group.run + examples_that_were_run.should == ["should be run"] end + end end - it "after(:all) should have access to all instance variables defined in before(:all)" do - context_instance_value_in = "Hello there" - context_instance_value_out = "" - example_group.before(:all) { @instance_var = context_instance_value_in } - example_group.after(:all) { context_instance_value_out = @instance_var } - example_group.it("test") {true} - example_group.run - context_instance_value_in.should == context_instance_value_out - end + describe ExampleGroup, "#run with success" do + before do + @special_example_group = Class.new(ExampleGroup) + ExampleGroupFactory.register(:special, @special_example_group) + @not_special_example_group = Class.new(ExampleGroup) + ExampleGroupFactory.register(:not_special, @not_special_example_group) + end - it "should copy instance variables from before(:all)'s execution context into spec's execution context" do - context_instance_value_in = "Hello there" - context_instance_value_out = "" - example_group.before(:all) { @instance_var = context_instance_value_in } - example_group.it("test") {context_instance_value_out = @instance_var} - example_group.run - context_instance_value_in.should == context_instance_value_out - end + after do + ExampleGroupFactory.reset + end - it "should not add global before callbacks for untargetted example_group" do - fiddle = [] + it "should send reporter add_example_group" do + example_group.run + reporter.example_groups.should == [example_group] + end - ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } - ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } - @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)" } + it "should run example on run" do + example_ran = false + example_group.it("should") {example_ran = true} + example_group.run + example_ran.should be_true + end - example_group = Class.new(ExampleGroup) do - describe("I'm not special", :type => :not_special) - it "does nothing" + it "should run before(:all) block only once" do + before_all_run_count_run_count = 0 + example_group.before(:all) {before_all_run_count_run_count += 1} + example_group.it("test") {true} + example_group.it("test2") {true} + example_group.run + before_all_run_count_run_count.should == 1 end - example_group.run - fiddle.should == [ - 'Example.prepend_before(:all)', - 'Example.before(:all)', - ] - end - - it "should add global before callbacks for targetted example_groups" do - fiddle = [] - - ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } - ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } - @special_example_group.before(:each) { fiddle << "special.before(:each, :type => :special)" } - @special_example_group.prepend_before(:each) { fiddle << "special.prepend_before(:each, :type => :special)" } - @special_example_group.before(:all) { fiddle << "special.before(:all, :type => :special)" } - @special_example_group.prepend_before(:all) { fiddle << "special.prepend_before(:all, :type => :special)" } - @special_example_group.append_before(:each) { fiddle << "special.append_before(:each, :type => :special)" } - example_group = Class.new(@special_example_group).describe("I'm a special example_group") {} - example_group.it("test") {true} - example_group.run - fiddle.should == [ - 'Example.prepend_before(:all)', - 'Example.before(:all)', - 'special.prepend_before(:all, :type => :special)', - 'special.before(:all, :type => :special)', - 'special.prepend_before(:each, :type => :special)', - 'special.before(:each, :type => :special)', - 'special.append_before(:each, :type => :special)', - ] - end - - it "should order before callbacks from global to local" do - fiddle = [] - ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } - ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } - example_group.prepend_before(:all) { fiddle << "prepend_before(:all)" } - example_group.before(:all) { fiddle << "before(:all)" } - example_group.prepend_before(:each) { fiddle << "prepend_before(:each)" } - example_group.before(:each) { fiddle << "before(:each)" } - example_group.run - fiddle.should == [ - 'Example.prepend_before(:all)', - 'Example.before(:all)', - 'prepend_before(:all)', - 'before(:all)', - 'prepend_before(:each)', - 'before(:each)' - ] - end - - it "should order after callbacks from local to global" do - fiddle = [] - example_group.after(:each) { fiddle << "after(:each)" } - example_group.append_after(:each) { fiddle << "append_after(:each)" } - example_group.after(:all) { fiddle << "after(:all)" } - example_group.append_after(:all) { fiddle << "append_after(:all)" } - ExampleGroup.after(:all) { fiddle << "Example.after(:all)" } - ExampleGroup.append_after(:all) { fiddle << "Example.append_after(:all)" } - example_group.run - fiddle.should == [ - 'after(:each)', - 'append_after(:each)', - 'after(:all)', - 'append_after(:all)', - 'Example.after(:all)', - 'Example.append_after(:all)' - ] - end + it "should run after(:all) block only once" do + after_all_run_count = 0 + example_group.after(:all) {after_all_run_count += 1} + example_group.it("test") {true} + example_group.it("test2") {true} + example_group.run + after_all_run_count.should == 1 + @reporter.rspec_verify + end - it "should have accessible instance methods from included module" do - mod1_method_called = false - mod1 = Module.new do - define_method :mod1_method do - mod1_method_called = true - end + it "after(:all) should have access to all instance variables defined in before(:all)" do + context_instance_value_in = "Hello there" + context_instance_value_out = "" + example_group.before(:all) { @instance_var = context_instance_value_in } + example_group.after(:all) { context_instance_value_out = @instance_var } + example_group.it("test") {true} + example_group.run + context_instance_value_in.should == context_instance_value_out end - mod2_method_called = false - mod2 = Module.new do - define_method :mod2_method do - mod2_method_called = true - end + it "should copy instance variables from before(:all)'s execution context into spec's execution context" do + context_instance_value_in = "Hello there" + context_instance_value_out = "" + example_group.before(:all) { @instance_var = context_instance_value_in } + example_group.it("test") {context_instance_value_out = @instance_var} + example_group.run + context_instance_value_in.should == context_instance_value_out end - example_group.include mod1, mod2 + it "should not add global before callbacks for untargetted example_group" do + fiddle = [] - example_group.it("test") do - mod1_method - mod2_method - end - example_group.run - mod1_method_called.should be_true - mod2_method_called.should be_true - end + ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } + ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } + @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)" } - it "should include targetted modules included using configuration" do - mod1 = Module.new - mod2 = Module.new - mod3 = Module.new - Spec::Runner.configuration.include(mod1, mod2) - Spec::Runner.configuration.include(mod3, :type => :not_special) + example_group = Class.new(ExampleGroup) do + describe("I'm not special", :type => :not_special) + it "does nothing" + end + example_group.run + fiddle.should == [ + 'Example.prepend_before(:all)', + 'Example.before(:all)', + ] + end + + it "should add global before callbacks for targetted example_groups" do + fiddle = [] + + ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } + ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } + @special_example_group.before(:each) { fiddle << "special.before(:each, :type => :special)" } + @special_example_group.prepend_before(:each) { fiddle << "special.prepend_before(:each, :type => :special)" } + @special_example_group.before(:all) { fiddle << "special.before(:all, :type => :special)" } + @special_example_group.prepend_before(:all) { fiddle << "special.prepend_before(:all, :type => :special)" } + @special_example_group.append_before(:each) { fiddle << "special.append_before(:each, :type => :special)" } - example_group = Class.new(@special_example_group).describe("I'm special", :type => :special) do - it "does nothing" + example_group = Class.new(@special_example_group).describe("I'm a special example_group") {} + example_group.it("test") {true} + example_group.run + fiddle.should == [ + 'Example.prepend_before(:all)', + 'Example.before(:all)', + 'special.prepend_before(:all, :type => :special)', + 'special.before(:all, :type => :special)', + 'special.prepend_before(:each, :type => :special)', + 'special.before(:each, :type => :special)', + 'special.append_before(:each, :type => :special)', + ] + end + + it "should order before callbacks from global to local" do + fiddle = [] + ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" } + ExampleGroup.before(:all) { fiddle << "Example.before(:all)" } + example_group.prepend_before(:all) { fiddle << "prepend_before(:all)" } + example_group.before(:all) { fiddle << "before(:all)" } + example_group.prepend_before(:each) { fiddle << "prepend_before(:each)" } + example_group.before(:each) { fiddle << "before(:each)" } + example_group.run + fiddle.should == [ + 'Example.prepend_before(:all)', + 'Example.before(:all)', + 'prepend_before(:all)', + 'before(:all)', + 'prepend_before(:each)', + 'before(:each)' + ] + end + + it "should order after callbacks from local to global" do + fiddle = [] + example_group.after(:each) { fiddle << "after(:each)" } + example_group.append_after(:each) { fiddle << "append_after(:each)" } + example_group.after(:all) { fiddle << "after(:all)" } + example_group.append_after(:all) { fiddle << "append_after(:all)" } + ExampleGroup.after(:all) { fiddle << "Example.after(:all)" } + ExampleGroup.append_after(:all) { fiddle << "Example.append_after(:all)" } + example_group.run + fiddle.should == [ + 'after(:each)', + 'append_after(:each)', + 'after(:all)', + 'append_after(:all)', + 'Example.after(:all)', + 'Example.append_after(:all)' + ] end - example_group.run - 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) + it "should have accessible instance methods from included module" do + mod1_method_called = false + mod1 = Module.new do + define_method :mod1_method do + mod1_method_called = true + end end - end - example_group.run - $included_predicate_matcher_found.should be(true) - end - it "should use a mock framework set up in config" do - mod = Module.new do - class << self - def included(mod) - $included_module = mod + mod2_method_called = false + mod2 = Module.new do + define_method :mod2_method do + mod2_method_called = true end end - def teardown_mocks_for_rspec - $torn_down = true + example_group.include mod1, mod2 + + example_group.it("test") do + mod1_method + mod2_method end + example_group.run + mod1_method_called.should be_true + mod2_method_called.should be_true end - begin - $included_module = nil - $torn_down = true - Spec::Runner.configuration.mock_with mod + it "should include targetted modules included using configuration" do + mod1 = Module.new + mod2 = Module.new + mod3 = Module.new + Spec::Runner.configuration.include(mod1, mod2) + Spec::Runner.configuration.include(mod3, :type => :not_special) - example_group = Class.new(ExampleGroup) do - describe('example') + example_group = Class.new(@special_example_group).describe("I'm special", :type => :special) do it "does nothing" end example_group.run - $included_module.should_not be_nil - $torn_down.should == true - ensure - Spec::Runner.configuration.mock_with :rspec + example_group.included_modules.should include(mod1) + example_group.included_modules.should include(mod2) + example_group.included_modules.should_not include(mod3) end - end - end - describe ExampleGroup, "#run with pending example that has a failing assertion" do - before do - example_group.it("should be pending") do - pending("Example fails") {false.should be_true} + 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 + $included_predicate_matcher_found.should be(true) end - end - it "should send example_pending to formatter" do - @formatter.should_receive(:example_pending).with("example", "should be pending", "Example fails") - example_group.run - end - end + it "should use a mock framework set up in config" do + mod = Module.new do + def self.included(mod) + $included_module = mod + end - describe ExampleGroup, "#run with pending example that does not have a failing assertion" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + def teardown_mocks_for_rspec + $torn_down = true + end + end + + begin + $included_module = nil + $torn_down = true + Spec::Runner.configuration.mock_with mod - before do - example_group.it("should be pending") do - pending("Example passes") {true.should be_true} + example_group = Class.new(ExampleGroup) do + describe('example') + it "does nothing" + end + example_group.run + + $included_module.should_not be_nil + $torn_down.should == true + ensure + Spec::Runner.configuration.mock_with :rspec + end end end - it "should send example_pending to formatter" do - @formatter.should_receive(:example_pending).with("example", "should be pending", "Example passes") - example_group.run + describe ExampleGroup, "#run with pending example that has a failing assertion" do + before do + example_group.it("should be pending") do + pending("Example fails") {false.should be_true} + end + end + + it "should send example_pending to formatter" do + @formatter.should_receive(:example_pending).with("example", "should be pending", "Example fails") + example_group.run + end end - end - describe ExampleGroup, "#run when before(:all) fails" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + describe ExampleGroup, "#run with pending example that does not have a failing assertion" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - before do - ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" } - end + before do + example_group.it("should be pending") do + pending("Example passes") {true.should be_true} + end + end - it "should not run any example" do - spec_ran = false - example_group.it("test") {spec_ran = true} - example_group.run - spec_ran.should be_false + it "should send example_pending to formatter" do + @formatter.should_receive(:example_pending).with("example", "should be pending", "Example passes") + example_group.run + end end - it "should run ExampleGroup after(:all)" do - after_all_ran = false - ExampleGroup.after(:all) { after_all_ran = true } - example_group.run - after_all_ran.should be_true - end + describe ExampleGroup, "#run when before(:all) fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - it "should run example_group after(:all)" do - after_all_ran = false - example_group.after(:all) { after_all_ran = true } - example_group.run - after_all_ran.should be_true - end + before do + ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" } + end - it "should supply before(:all) as description" do - @reporter.should_receive(:failure) do |example, error| - example.description.should eql("before(:all)") - error.message.should eql("before(:all) failure") + it "should not run any example" do + spec_ran = false + example_group.it("test") {spec_ran = true} + example_group.run + spec_ran.should be_false end - example_group.it("test") {true} - example_group.run - end - end + it "should run ExampleGroup after(:all)" do + after_all_ran = false + ExampleGroup.after(:all) { after_all_ran = true } + example_group.run + after_all_ran.should be_true + end - describe ExampleGroup, "#run when before(:each) fails" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + it "should run example_group after(:all)" do + after_all_ran = false + example_group.after(:all) { after_all_ran = true } + example_group.run + after_all_ran.should be_true + end - before do - ExampleGroup.before(:each) { raise NonStandardError } - end + it "should supply before(:all) as description" do + @reporter.should_receive(:failure) do |example, error| + example.description.should eql("before(:all)") + error.message.should eql("before(:all) failure") + end - it "should run after(:all)" do - after_all_ran = false - ExampleGroup.after(:all) { after_all_ran = true } - example_group.run - after_all_ran.should be_true + example_group.it("test") {true} + example_group.run + end end - end - describe ExampleGroup, "#run when any example fails" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + describe ExampleGroup, "#run when before(:each) fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - before do - example_group.it("should") { raise NonStandardError } - end + before do + ExampleGroup.before(:each) { raise NonStandardError } + end - it "should run after(:all)" do - after_all_ran = false - ExampleGroup.after(:all) { after_all_ran = true } - example_group.run - after_all_ran.should be_true + it "should run after(:all)" do + after_all_ran = false + ExampleGroup.after(:all) { after_all_ran = true } + example_group.run + after_all_ran.should be_true + end end - end - describe ExampleGroup, "#run when first after(:each) block fails" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + describe ExampleGroup, "#run when any example fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - before do - class << example_group - attr_accessor :first_after_ran, :second_after_ran + before do + example_group.it("should") { raise NonStandardError } end - example_group.first_after_ran = false - example_group.second_after_ran = false - example_group.after(:each) do - self.class.second_after_ran = true - end - example_group.after(:each) do - self.class.first_after_ran = true - raise "first" + it "should run after(:all)" do + after_all_ran = false + ExampleGroup.after(:all) { after_all_ran = true } + example_group.run + after_all_ran.should be_true end end - it "should run second after(:each) block" do - reporter.should_receive(:example_finished) do |example, error| - example.should equal(example) - error.message.should eql("first") - end - example_group.run - example_group.first_after_ran.should be_true - example_group.second_after_ran.should be_true - end - end + describe ExampleGroup, "#run when first after(:each) block fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - describe ExampleGroup, "#run when first before(:each) block fails" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + before do + class << example_group + attr_accessor :first_after_ran, :second_after_ran + end + example_group.first_after_ran = false + example_group.second_after_ran = false - before do - class << example_group - attr_accessor :first_before_ran, :second_before_ran + example_group.after(:each) do + self.class.second_after_ran = true + end + example_group.after(:each) do + self.class.first_after_ran = true + raise "first" + end end - example_group.first_before_ran = false - example_group.second_before_ran = false - example_group.before(:each) do - self.class.first_before_ran = true - raise "first" - end - example_group.before(:each) do - self.class.second_before_ran = true + it "should run second after(:each) block" do + reporter.should_receive(:example_finished) do |example, error| + example.should equal(example) + error.message.should eql("first") + end + example_group.run + example_group.first_after_ran.should be_true + example_group.second_after_ran.should be_true end end - it "should not run second before(:each)" do - reporter.should_receive(:example_finished) do |name, error| - error.message.should eql("first") + describe ExampleGroup, "#run when first before(:each) block fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + + before do + class << example_group + attr_accessor :first_before_ran, :second_before_ran + end + example_group.first_before_ran = false + example_group.second_before_ran = false + + example_group.before(:each) do + self.class.first_before_ran = true + raise "first" + end + example_group.before(:each) do + self.class.second_before_ran = true + end + end + + it "should not run second before(:each)" do + reporter.should_receive(:example_finished) do |name, error| + error.message.should eql("first") + end + example_group.run + example_group.first_before_ran.should be_true + example_group.second_before_ran.should be_false end - example_group.run - example_group.first_before_ran.should be_true - example_group.second_before_ran.should be_false end - end - describe ExampleGroup, "#run when failure in after(:all)" do - it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + describe ExampleGroup, "#run when failure in after(:all)" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" - before do - ExampleGroup.after(:all) { raise NonStandardError, "in after(:all)" } - end + before do + ExampleGroup.after(:all) { raise NonStandardError, "in after(:all)" } + end - it "should return false" do - example_group.run.should be_false + it "should return false" do + example_group.run.should be_false + end end end end @@ -659,7 +659,7 @@ example_group = Class.new(ExampleSubclass) do describe(Array) end - example_group.send(:described_type).should == Array + example_group.__send__(:described_type).should == Array end it "should concat descriptions when nested" do @@ -671,53 +671,5 @@ $nested_group.description.to_s.should == "Array when empty" end end - - describe Enumerable do - before(:each) do - Kernel.stub!(:warn) - end - - def each(&block) - ["4", "2", "1"].each(&block) - end - - it "should be included in examples because it is a module" do - map{|e| e.to_i}.should == [4,2,1] - end - end - - describe "An", Enumerable, "as a second argument" do - before(:each) do - Kernel.stub!(:warn) - end - - def each(&block) - ["4", "2", "1"].each(&block) - end - - it "should be included in examples because it is a module" do - map{|e| e.to_i}.should == [4,2,1] - end - end - - describe Enumerable do - describe "as the parent of nested example groups" do - before(:each) do - Kernel.stub!(:warn) - end - - it "should be included in examples because it is a module" do - pending("need to make sure nested groups know the described type") do - map{|e| e.to_i}.should == [4,2,1] - end - end - end - end - - describe String do - it "should not be included in examples because it is not a module" do - lambda{self.map}.should raise_error(NoMethodError, /undefined method `map' for/) - end - end end end Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb Wed Dec 10 17:34:18 2008 @@ -2,31 +2,14 @@ module Spec module Example - module ExampleMatcherSpecHelper - class MatchDescription - def initialize(description) - @description = description - end - - def matches?(matcher) - matcher.matches?(@description) - end - - def failure_message - "expected matcher.matches?(#{@description.inspect}) to return true, got false" - end - - def negative_failure_message - "expected matcher.matches?(#{@description.inspect}) to return false, got true" - end - end + describe ExampleMatcher, "#matches?" do def match_description(description) - MatchDescription.new(description) + simple_matcher do |actual, matcher| + matcher.failure_message = "expected matcher.matches?(#{description.inspect}) to return true, got false" + matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true" + actual.matches?(description) + end end - end - - describe ExampleMatcher, "#matches?" do - include ExampleMatcherSpecHelper it "should match correct example_group and example" do matcher = ExampleMatcher.new("example_group", "example") Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb Wed Dec 10 17:34:18 2008 @@ -22,105 +22,300 @@ end describe "lifecycle" do - before do - @original_rspec_options = $rspec_options - @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new) - $rspec_options = @options - @options.formatters << mock("formatter", :null_object => true) - @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true) - @reporter = FakeReporter.new(@options) - @options.reporter = @reporter + with_sandboxed_options do + before do + @options.formatters << mock("formatter", :null_object => true) + @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true) + @reporter = FakeReporter.new(@options) + @options.reporter = @reporter + + ExampleGroup.before_all_parts.should == [] + ExampleGroup.before_each_parts.should == [] + ExampleGroup.after_each_parts.should == [] + ExampleGroup.after_all_parts.should == [] + def ExampleGroup.count + @count ||= 0 + @count = @count + 1 + @count + end + end - ExampleMethods.before_all_parts.should == [] - ExampleMethods.before_each_parts.should == [] - ExampleMethods.after_each_parts.should == [] - ExampleMethods.after_all_parts.should == [] - def ExampleMethods.count - @count ||= 0 - @count = @count + 1 - @count + after do + ExampleGroup.instance_variable_set("@before_all_parts", []) + ExampleGroup.instance_variable_set("@before_each_parts", []) + ExampleGroup.instance_variable_set("@after_each_parts", []) + ExampleGroup.instance_variable_set("@after_all_parts", []) end - end - after do - $rspec_options = @original_rspec_options - ExampleMethods.instance_variable_set("@before_all_parts", []) - ExampleMethods.instance_variable_set("@before_each_parts", []) - ExampleMethods.instance_variable_set("@after_each_parts", []) - ExampleMethods.instance_variable_set("@after_all_parts", []) - end + it "should pass before and after callbacks to all ExampleGroup subclasses" do + ExampleGroup.before(:suite) do + ExampleGroup.count.should == 1 + end - it "should pass before and after callbacks to all ExampleGroup subclasses" do - ExampleMethods.before(:suite) do - ExampleMethods.count.should == 1 - end + ExampleGroup.before(:all) do + ExampleGroup.count.should == 2 + end - ExampleMethods.before(:all) do - ExampleMethods.count.should == 2 - end + ExampleGroup.before(:each) do + ExampleGroup.count.should == 3 + end - ExampleMethods.before(:each) do - ExampleMethods.count.should == 3 - end + ExampleGroup.after(:each) do + ExampleGroup.count.should == 4 + end - ExampleMethods.after(:each) do - ExampleMethods.count.should == 4 - end + ExampleGroup.after(:all) do + ExampleGroup.count.should == 5 + end - ExampleMethods.after(:all) do - ExampleMethods.count.should == 5 - end + ExampleGroup.after(:suite) do + ExampleGroup.count.should == 6 + end - ExampleMethods.after(:suite) do - ExampleMethods.count.should == 6 + Class.new(ExampleGroup) do + it "should use ExampleMethods callbacks" do end + end + @options.run_examples + ExampleGroup.count.should == 7 end - @example_group = Class.new(ExampleGroup) do - it "should use ExampleMethods callbacks" do + describe "eval_block" do + before(:each) do + @example_group = Class.new(ExampleGroup) + end + + describe "with a given description" do + it "should provide the given description" do + @example = @example_group.it("given description") { 2.should == 2 } + @example.eval_block + @example.description.should == "given description" + end + end + + describe "with no given description" do + it "should provide the generated description" do + @example = @example_group.it { 2.should == 2 } + @example.eval_block + @example.description.should == "should == 2" + end + end + + describe "with no implementation" do + it "should raise an NotYetImplementedError" do + lambda { + @example = @example_group.it + @example.eval_block + }.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented") + end + + def extract_error(&blk) + begin + blk.call + rescue Exception => e + return e + end + + nil + end + + it "should use the proper file and line number for the NotYetImplementedError" do + file = __FILE__ + line_number = __LINE__ + 3 + + error = extract_error do + @example = @example_group.it + @example.eval_block + end + + error.pending_caller.should == "#{file}:#{line_number}" + end end end - @options.run_examples - ExampleMethods.count.should == 7 end + end - describe "run_with_description_capturing" do + describe "#backtrace" do + with_sandboxed_options do + it "returns the backtrace from where the example was defined" do + example_group = Class.new(ExampleGroup) do + example "of something" do; end + end + + example = example_group.examples.first + example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}") + end + end + end + + describe "#implementation_backtrace (deprecated)" do + with_sandboxed_options do before(:each) do - @example_group = Class.new(ExampleGroup) do end - @example = @example_group.new("foo", &(lambda { 2.should == 2 })) - @example.run_with_description_capturing + Kernel.stub!(:warn) end - it "should provide the generated description" do - @example.instance_eval { @_matcher_description }.should == "should == 2" + it "sends a deprecation warning" do + example_group = Class.new(ExampleGroup) {} + example = example_group.example("") {} + Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m) + example.implementation_backtrace + end + + it "returns the backtrace from where the example was defined" do + example_group = Class.new(ExampleGroup) do + example "of something" do; end + end + + example = example_group.examples.first + example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}") end + end + end - it "should clear the global generated_description" do - Spec::Matchers.generated_description.should == nil + describe "#full_description" do + it "should return the full description of the ExampleGroup and Example" do + example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do + it "should do something" do + end + end + example = example_group.examples.first + example.full_description.should == "An ExampleGroup should do something" + end + end + + describe "#subject" do + with_sandboxed_options do + it "should return an instance variable named after the described type" do + example_group = Class.new(ExampleGroup).describe(Array) do + example {} + end + example = example_group.examples.first + example.subject.should == [] + end + + it "should not barf on a module (as opposed to a class)" do + example_group = Class.new(ExampleGroup).describe(ObjectSpace) do + example {} + end + example_group.examples.first.subject.should be_nil + end + + it "should not barf on a string" do + example_group = Class.new(ExampleGroup).describe('foo') do + example {} + end + example_group.examples.first.subject.should be_nil + end + + it "should interact with the same scope as the before block" do + example_group = Class.new(ExampleGroup) do + subject { @foo = 'foo'} + example { should == @foo} + it { should == 'foo'} + end + example_group.run.should be_true end end end - describe "#implementation_backtrace" do - it "returns the backtrace of where the implementation was defined" do - example_group = Class.new(ExampleGroup) do - it "should use ExampleMethods callbacks" do + describe "#should" do + with_sandboxed_options do + class Thing + def ==(other) + true end end - example = example_group.examples.first - example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}") + + describe "in an ExampleGroup with the ivar defined in before" do + attr_reader :example, :success + + before(:each) do + example_group = describe(Thing, "1") do + before(:each) { @spec_example_thing = 'expected' } + it { should eql('expected') } + end + @example = example_group.examples.first + @success = example_group.run + end + + it "should create an example using the description from the matcher" do + example.description.should == 'should eql "expected"' + end + + it "should test the matcher returned from the block" do + success.should be_true + end + end + + describe "in an ExampleGroup with the subject defined using #subject" do + it "should create an example using the description from the matcher" do + example_group = describe(Thing, "2") do + subject {'this is the subject'} + it { should eql('this is the subject') } + end + example = example_group.examples.first + example_group.run + example.description.should =~ /should eql "this is the subject"/ + end + end + + describe "in an ExampleGroup using an implicit ivar" do + it "should create an example using the description from the matcher" do + example_group = describe(Thing, "3") do + it { should == Thing.new } + end + example = example_group.examples.first + success = example_group.run + example.description.should =~ /should == # 'that' do; end + example.options[:this].should == 'that' + end + end + end -end \ No newline at end of file +end Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/helper_method_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/helper_method_spec.rb?rev=725524&view=auto ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/helper_method_spec.rb (added) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/helper_method_spec.rb Wed Dec 10 17:34:18 2008 @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +# This was added to prove that http://rspec.lighthouseapp.com/projects/5645/tickets/211 +# was fixed in ruby 1.9.1 + +module HelperMethodExample + describe "a helper method" do + def helper_method + "received call" + end + + it "is available to examples in the same group" do + helper_method.should == "received call" + end + + describe "from a nested group" do + it "is available to examples in a nested group" do + helper_method.should == "received call" + end + end + + end +end + Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb Wed Dec 10 17:34:18 2008 @@ -4,28 +4,136 @@ it 'should raise an ExamplePendingError if no block is supplied' do lambda { - include Pending pending "TODO" }.should raise_error(ExamplePendingError, /TODO/) end it 'should raise an ExamplePendingError if a supplied block fails as expected' do lambda { - include Pending pending "TODO" do raise "oops" end }.should raise_error(ExamplePendingError, /TODO/) end + it 'should raise an ExamplePendingError if a supplied block fails as expected with a mock' do + lambda { + pending "TODO" do + m = mock('thing') + m.should_receive(:foo) + m.rspec_verify + end + }.should raise_error(ExamplePendingError, /TODO/) + end + it 'should raise a PendingExampleFixedError if a supplied block starts working' do lambda { - include Pending pending "TODO" do # success! end }.should raise_error(PendingExampleFixedError, /TODO/) end + + it "should have the correct file and line number for pending given with a block which fails" do + file = __FILE__ + line_number = __LINE__ + 2 + begin + pending do + raise + end + rescue => error + error.pending_caller.should == "#{file}:#{line_number}" + end + end + + it "should have the correct file and line number for pending given with no block" do + file = __FILE__ + line_number = __LINE__ + 2 + begin + pending("TODO") + rescue => error + error.pending_caller.should == "#{file}:#{line_number}" + end + end + end + + describe ExamplePendingError do + it "should have the caller (from two calls from initialization)" do + two_calls_ago = caller[0] + ExamplePendingError.new("a message").pending_caller.should == two_calls_ago + end + + it "should keep the trace information from initialization" do + two_calls_ago = caller[0] + obj = ExamplePendingError.new("a message") + obj.pending_caller + def another_caller(obj) + obj.pending_caller + end + + another_caller(obj).should == two_calls_ago + end + + it "should have the message provided" do + ExamplePendingError.new("a message").message.should == "a message" + end + + it "should use a 'ExamplePendingError' as it's default message" do + ExamplePendingError.new.message.should == "Spec::Example::ExamplePendingError" + end + end + + describe NotYetImplementedError do + def rspec_root + File.expand_path(__FILE__.gsub("/spec/spec/example/pending_module_spec.rb", "/lib")) + end + + it "should have the root rspec path" do + NotYetImplementedError::RSPEC_ROOT_LIB.should == rspec_root + end + + it "should always have the error 'Not Yet Implemented'" do + NotYetImplementedError.new([]).message.should == "Not Yet Implemented" + end + + describe "pending_caller" do + it "should select an element out of the backtrace" do + error = NotYetImplementedError.new(["foo/bar.rb:18"]) + + error.pending_caller.should == "foo/bar.rb:18" + end + + it "should actually report the element from the backtrace" do + error = NotYetImplementedError.new(["bar.rb:18"]) + + error.pending_caller.should == "bar.rb:18" + end + + it "should not use an element with the rspec root path" do + error = NotYetImplementedError.new(["#{rspec_root}:8"]) + + error.pending_caller.should be_nil + end + + it "should select the first line in the backtrace which isn't in the rspec root" do + error = NotYetImplementedError.new([ + "#{rspec_root}/foo.rb:2", + "#{rspec_root}/foo/bar.rb:18", + "path1.rb:22", + "path2.rb:33" + ]) + + error.pending_caller.should == "path1.rb:22" + end + + it "should cache the caller" do + backtrace = mock('backtrace') + backtrace.should_receive(:detect).once + + error = NotYetImplementedError.new(backtrace) + error.pending_caller.should == error.pending_caller + end + end end end end Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb Wed Dec 10 17:34:18 2008 @@ -3,262 +3,254 @@ module Spec module Example describe ExampleGroup, "with :shared => true" do - it_should_behave_like "sandboxed rspec_options" - attr_reader :formatter, :example_group - before(:each) do - @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true) - options.formatters << formatter - @example_group = Class.new(ExampleGroup).describe("example_group") - class << example_group - public :include + with_sandboxed_options do + attr_reader :formatter, :example_group + before(:each) do + @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true) + options.formatters << formatter + @example_group = Class.new(ExampleGroup).describe("example_group") + class << example_group + public :include + end end - end - - after(:each) do - @formatter.rspec_verify - @example_group = nil - $shared_example_groups.clear unless $shared_example_groups.nil? - end - - def make_shared_example_group(name, opts=nil, &block) - example_group = SharedExampleGroup.new(name, :shared => true, &block) - SharedExampleGroup.add_shared_example_group(example_group) - example_group - end - - def non_shared_example_group() - @non_shared_example_group ||= Class.new(ExampleGroup).describe("example_group") - end - - it "should accept an optional options hash" do - lambda { Class.new(ExampleGroup).describe("context") }.should_not raise_error(Exception) - lambda { Class.new(ExampleGroup).describe("context", :shared => true) }.should_not raise_error(Exception) - end - it "should return all shared example_groups" do - b1 = make_shared_example_group("b1", :shared => true) {} - b2 = make_shared_example_group("b2", :shared => true) {} - - b1.should_not be(nil) - b2.should_not be(nil) - - SharedExampleGroup.find_shared_example_group("b1").should equal(b1) - SharedExampleGroup.find_shared_example_group("b2").should equal(b2) - end - - it "should register as shared example_group" do - example_group = make_shared_example_group("example_group") {} - SharedExampleGroup.shared_example_groups.should include(example_group) - end - - it "should not be shared when not configured as shared" do - example_group = non_shared_example_group - SharedExampleGroup.shared_example_groups.should_not include(example_group) - end + after(:each) do + @formatter.rspec_verify + @example_group = nil + Spec::Example::SharedExampleGroup.clear + end + + describe "#register" do + it "creates a new shared example group with the submitted args" do + block = lambda {} + group = SharedExampleGroup.new("shared group") do end + Spec::Example::SharedExampleGroup.should_receive(:new).with("share me", &block).and_return(group) + Spec::Example::SharedExampleGroup.register("share me", &block) + end - it "should complain when adding a second shared example_group with the same description" do - describe "shared example_group", :shared => true do + it "registers the shared example group" do + lambda do + Spec::Example::SharedExampleGroup.register "share me" do end + end.should change {Spec::Example::SharedExampleGroup.count}.by(1) + end end - lambda do + + it "complains when adding a second shared example_group with the same description" do describe "shared example_group", :shared => true do end - end.should raise_error(ArgumentError) - end - - it "should NOT complain when adding the same shared example_group instance again" do - shared_example_group = Class.new(ExampleGroup).describe("shared example_group", :shared => true) - SharedExampleGroup.add_shared_example_group(shared_example_group) - SharedExampleGroup.add_shared_example_group(shared_example_group) - end + lambda do + describe "shared example_group", :shared => true do + end + end.should raise_error(ArgumentError) + end + + it "does NOT add the same group twice" do + lambda do + 2.times do + describe "shared example_group which gets loaded twice", :shared => true do + end + end + end.should change {Spec::Example::SharedExampleGroup.count}.by(1) + end - it "should NOT complain when adding the same shared example_group again (i.e. file gets reloaded)" do - lambda do - 2.times do - describe "shared example_group which gets loaded twice", :shared => true do + it "does NOT complain when adding the same shared example_group again (i.e. file gets reloaded)" do + lambda do + 2.times do + describe "shared example_group which gets loaded twice", :shared => true do + end end + end.should_not raise_error(ArgumentError) + end + + it "does NOT complain when adding the same shared example_group in same file with different absolute path" do + SharedExampleGroup.register( + "shared example_group", + :shared => true, + :spec_path => "/my/spec/a/../shared.rb" + ) + SharedExampleGroup.register( + "shared example_group", + :shared => true, + :spec_path => "/my/spec/b/../shared.rb" + ) + end + + it "complains when adding a different shared example_group with the same name in a different file with the same basename" do + SharedExampleGroup.register( + "shared example_group", + :shared => true, + :spec_path => "/my/spec/a/shared.rb" + ) + lambda do + SharedExampleGroup.register( + "shared example_group", + :shared => true, + :spec_path => "/my/spec/b/shared.rb" + ) + end.should raise_error(ArgumentError, /already exists/) + end + + it "adds examples to current example_group using it_should_behave_like" do + shared_example_group = SharedExampleGroup.register("shared example_group") do + it("shared example") {} + it("shared example 2") {} end - end.should_not raise_error(ArgumentError) - end - it "should NOT complain when adding the same shared example_group in same file with different absolute path" do - shared_example_group_1 = Class.new(ExampleGroup).describe( - "shared example_group", - :shared => true, - :spec_path => "/my/spec/a/../shared.rb" - ) - shared_example_group_2 = Class.new(ExampleGroup).describe( - "shared example_group", - :shared => true, - :spec_path => "/my/spec/b/../shared.rb" - ) + example_group.it("example") {} + example_group.number_of_examples.should == 1 + example_group.it_should_behave_like("shared example_group") + example_group.number_of_examples.should == 3 + end - SharedExampleGroup.add_shared_example_group(shared_example_group_1) - SharedExampleGroup.add_shared_example_group(shared_example_group_2) - end + it "adds examples to from two shared groups" do + shared_example_group_1 = SharedExampleGroup.register("shared example_group 1") do + it("shared example 1") {} + end - it "should complain when adding a different shared example_group with the same name in a different file with the same basename" do - shared_example_group_1 = Class.new(ExampleGroup).describe( - "shared example_group", - :shared => true, - :spec_path => "/my/spec/a/shared.rb" - ) - shared_example_group_2 = Class.new(ExampleGroup).describe( - "shared example_group", - :shared => true, - :spec_path => "/my/spec/b/shared.rb" - ) - - SharedExampleGroup.add_shared_example_group(shared_example_group_1) - lambda do - SharedExampleGroup.add_shared_example_group(shared_example_group_2) - end.should raise_error(ArgumentError, /already exists/) - end + shared_example_group_1 = SharedExampleGroup.register("shared example_group 2") do + it("shared example 2") {} + end - it "should add examples to current example_group using it_should_behave_like" do - shared_example_group = make_shared_example_group("shared example_group") do - it("shared example") {} - it("shared example 2") {} + example_group.it("example") {} + example_group.number_of_examples.should == 1 + example_group.it_should_behave_like("shared example_group 1", "shared example_group 2") + example_group.number_of_examples.should == 3 end - example_group.it("example") {} - example_group.number_of_examples.should == 1 - example_group.it_should_behave_like("shared example_group") - example_group.number_of_examples.should == 3 - end - - it "should add examples to current example_group using include" do - shared_example_group = describe "all things", :shared => true do - it "should do stuff" do end - end + it "adds examples to current example_group using include" do + shared_example_group = describe "all things", :shared => true do + it "should do stuff" do end + end - example_group = describe "one thing" do - include shared_example_group - end + example_group = describe "one thing" do + include shared_example_group + end - example_group.number_of_examples.should == 1 - end - - it "should add examples to current example_group using it_should_behave_like with a module" do - AllThings = describe "all things", :shared => true do - it "should do stuff" do end + example_group.number_of_examples.should == 1 end + + it "adds examples to current example_group using it_should_behave_like with a module" do + AllThings = describe "all things", :shared => true do + it "should do stuff" do end + end - example_group = describe "one thing" do - it_should_behave_like AllThings - end + example_group = describe "one thing" do + it_should_behave_like AllThings + end - example_group.number_of_examples.should == 1 - end - - it "should run shared examples" do - shared_example_ran = false - shared_example_group = make_shared_example_group("shared example_group") do - it("shared example") { shared_example_ran = true } + example_group.number_of_examples.should == 1 end - example_ran = false - - example_group.it_should_behave_like("shared example_group") - example_group.it("example") {example_ran = true} - example_group.run - example_ran.should be_true - shared_example_ran.should be_true - end + it "runs shared examples" do + shared_example_ran = false + shared_example_group = SharedExampleGroup.register("shared example_group") do + it("shared example") { shared_example_ran = true } + end - it "should run setup and teardown from shared example_group" do - shared_setup_ran = false - shared_teardown_ran = false - shared_example_group = make_shared_example_group("shared example_group") do - before { shared_setup_ran = true } - after { shared_teardown_ran = true } - it("shared example") { shared_example_ran = true } - end - - example_ran = false - - example_group.it_should_behave_like("shared example_group") - example_group.it("example") {example_ran = true} - example_group.run - example_ran.should be_true - shared_setup_ran.should be_true - shared_teardown_ran.should be_true - end + example_ran = false - it "should run before(:all) and after(:all) only once from shared example_group" do - shared_before_all_run_count = 0 - shared_after_all_run_count = 0 - shared_example_group = make_shared_example_group("shared example_group") do - before(:all) { shared_before_all_run_count += 1} - after(:all) { shared_after_all_run_count += 1} - it("shared example") { shared_example_ran = true } - end - - example_ran = false - - example_group.it_should_behave_like("shared example_group") - example_group.it("example") {example_ran = true} - example_group.run - example_ran.should be_true - shared_before_all_run_count.should == 1 - shared_after_all_run_count.should == 1 - end + example_group.it_should_behave_like("shared example_group") + example_group.it("example") {example_ran = true} + example_group.run + example_ran.should be_true + shared_example_ran.should be_true + end + + it "runs before(:each) and after(:each) from shared example_group" do + shared_setup_ran = false + shared_teardown_ran = false + shared_example_group = SharedExampleGroup.register("shared example_group") do + before(:each) { shared_setup_ran = true } + after(:each) { shared_teardown_ran = true } + it("shared example") { shared_example_ran = true } + end + + example_ran = false - it "should include modules, included into shared example_group, into current example_group" do - @formatter.should_receive(:add_example_group).with(any_args) + example_group.it_should_behave_like("shared example_group") + example_group.it("example") {example_ran = true} + example_group.run + example_ran.should be_true + shared_setup_ran.should be_true + shared_teardown_ran.should be_true + end + + it "should run before(:all) and after(:all) only once from shared example_group" do + shared_before_all_run_count = 0 + shared_after_all_run_count = 0 + shared_example_group = SharedExampleGroup.register("shared example_group") do + before(:all) { shared_before_all_run_count += 1} + after(:all) { shared_after_all_run_count += 1} + it("shared example") { shared_example_ran = true } + end - shared_example_group = make_shared_example_group("shared example_group") do - it("shared example") { shared_example_ran = true } + example_ran = false + + example_group.it_should_behave_like("shared example_group") + example_group.it("example") {example_ran = true} + example_group.run + example_ran.should be_true + shared_before_all_run_count.should == 1 + shared_after_all_run_count.should == 1 end - mod1_method_called = false - mod1 = Module.new do - define_method :mod1_method do - mod1_method_called = true + it "should include modules, included into shared example_group, into current example_group" do + @formatter.should_receive(:add_example_group).with(any_args) + + shared_example_group = SharedExampleGroup.register("shared example_group") do + it("shared example") { shared_example_ran = true } end - end - mod2_method_called = false - mod2 = Module.new do - define_method :mod2_method do - mod2_method_called = true + mod1_method_called = false + mod1 = Module.new do + define_method :mod1_method do + mod1_method_called = true + end + end + + mod2_method_called = false + mod2 = Module.new do + define_method :mod2_method do + mod2_method_called = true + end end - end - shared_example_group.include mod2 + shared_example_group.__send__ :include, mod2 - example_group.it_should_behave_like("shared example_group") - example_group.include mod1 + example_group.it_should_behave_like("shared example_group") + example_group.include mod1 - example_group.it("test") do - mod1_method - mod2_method + example_group.it("test") do + mod1_method + mod2_method + end + example_group.run + mod1_method_called.should be_true + mod2_method_called.should be_true end - example_group.run - mod1_method_called.should be_true - mod2_method_called.should be_true - end - it "should make methods defined in the shared example_group available in consuming example_group" do - shared_example_group = make_shared_example_group("shared example_group xyz") do - def a_shared_helper_method - "this got defined in a shared example_group" + it "should make methods defined in the shared example_group available in consuming example_group" do + shared_example_group = SharedExampleGroup.register("shared example_group xyz") do + def a_shared_helper_method + "this got defined in a shared example_group" + end end + example_group.it_should_behave_like("shared example_group xyz") + success = false + example_group.it("should access a_shared_helper_method") do + a_shared_helper_method + success = true + end + example_group.run + success.should be_true end - example_group.it_should_behave_like("shared example_group xyz") - success = false - example_group.it("should access a_shared_helper_method") do - a_shared_helper_method - success = true - end - example_group.run - success.should be_true - end - it "should raise when named shared example_group can not be found" do - lambda { - example_group.it_should_behave_like("non-existent shared example group") - violated - }.should raise_error("Shared Example Group 'non-existent shared example group' can not be found") + it "should raise when named shared example_group can not be found" do + lambda { + example_group.it_should_behave_like("non-existent shared example group") + violated + }.should raise_error("Shared Example Group 'non-existent shared example group' can not be found") + end end end end Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/extensions/object_spec.rb URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/extensions/object_spec.rb?rev=725524&r1=725523&r2=725524&view=diff ============================================================================== --- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/extensions/object_spec.rb (original) +++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/expectations/extensions/object_spec.rb Wed Dec 10 17:34:18 2008 @@ -39,12 +39,6 @@ }.should raise_error(Spec::Expectations::InvalidMatcherError) end - it "should raise error if it receives nil" do - lambda { - @target.should nil - }.should raise_error(Spec::Expectations::InvalidMatcherError) - end - it "should raise error if it receives no argument and it is not used as a left side of an operator" do pending "Is it even possible to catch this?" lambda { @@ -92,12 +86,6 @@ }.should raise_error(Spec::Expectations::InvalidMatcherError) end - it "should raise error if it receives nil" do - lambda { - @target.should_not nil - }.should raise_error(Spec::Expectations::InvalidMatcherError) - end - it "should raise error if it receives no argument and it is not used as a left side of an operator" do pending "Is it even possible to catch this?" lambda {