diff options
author | francis <francis> | 2008-01-23 01:57:59 +0000 |
---|---|---|
committer | francis <francis> | 2008-01-23 01:57:59 +0000 |
commit | 6d1733e8a0b5f404326cfbd78b7139c87ecbffa3 (patch) | |
tree | c86561445b9ec5179020f8f56afb7b9174b390c5 /vendor/plugins/rspec/spec | |
parent | 8bd6667c7885870af45522315f501a2b87340b1a (diff) |
Add files new to new rspec
Diffstat (limited to 'vendor/plugins/rspec/spec')
55 files changed, 6475 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/spec/rspec_suite.rb b/vendor/plugins/rspec/spec/rspec_suite.rb new file mode 100644 index 000000000..ae076bbf1 --- /dev/null +++ b/vendor/plugins/rspec/spec/rspec_suite.rb @@ -0,0 +1,7 @@ +if __FILE__ == $0 + dir = File.dirname(__FILE__) + Dir["#{dir}/**/*_spec.rb"].each do |file| +# puts "require '#{file}'" + require file + end +end diff --git a/vendor/plugins/rspec/spec/ruby_forker.rb b/vendor/plugins/rspec/spec/ruby_forker.rb new file mode 100644 index 000000000..6ab038750 --- /dev/null +++ b/vendor/plugins/rspec/spec/ruby_forker.rb @@ -0,0 +1,13 @@ +require 'rbconfig' + +module RubyForker + # Forks a ruby interpreter with same type as ourself. + # juby will fork jruby, ruby will fork ruby etc. + def ruby(args, stderr=nil) + config = ::Config::CONFIG + interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT'] + cmd = "#{interpreter} #{args}" + cmd << " 2> #{stderr}" unless stderr.nil? + `#{cmd}` + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/example/configuration_spec.rb b/vendor/plugins/rspec/spec/spec/example/configuration_spec.rb new file mode 100644 index 000000000..5b4a6049e --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/configuration_spec.rb @@ -0,0 +1,282 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Example + + describe Configuration do + before(:each) do + @config = Configuration.new + @example_group = mock("example_group") + end + + describe "#mock_with" do + + it "should default mock framework to rspec" do + @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/ + end + + it "should let you set rspec mocking explicitly" do + @config.mock_with(:rspec) + @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/ + end + + it "should let you set mocha" do + @config.mock_with(:mocha) + @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/mocha$/ + end + + it "should let you set flexmock" do + @config.mock_with(:flexmock) + @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/flexmock$/ + end + + it "should let you set rr" do + @config.mock_with(:rr) + @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rr$/ + end + + it "should let you set an arbitrary adapter module" do + adapter = Module.new + @config.mock_with(adapter) + @config.mock_framework.should == adapter + end + end + + describe "#include" do + + before do + @original_configuration = Spec::Runner.configuration + spec_configuration = @config + Spec::Runner.instance_eval {@configuration = spec_configuration} + @example_group_class = Class.new(ExampleGroup) do + class << self + def this_class_has_special_methods + end + end + end + ExampleGroupFactory.register(:foobar, @example_group_class) + end + + after do + original_configuration = @original_configuration + Spec::Runner.instance_eval {@configuration = original_configuration} + ExampleGroupFactory.reset + end + + it "should include the submitted module in ExampleGroup subclasses" do + mod = Module.new + @config.include mod + Class.new(@example_group_class).included_modules.should include(mod) + end + + it "should let you define modules to be included for a specific type" do + mod = Module.new + @config.include mod, :type => :foobar + Class.new(@example_group_class).included_modules.should include(mod) + end + + it "should not include modules in a type they are not intended for" do + mod = Module.new + @other_example_group_class = Class.new(ExampleGroup) + ExampleGroupFactory.register(:baz, @other_example_group_class) + + @config.include mod, :type => :foobar + + Class.new(@other_example_group_class).included_modules.should_not include(mod) + end + + end + + end + + describe Configuration do + + before(:each) do + @config = Configuration.new + @special_example_group = Class.new(ExampleGroup) + @special_child_example_group = Class.new(@special_example_group) + @nonspecial_example_group = Class.new(ExampleGroup) + ExampleGroupFactory.register(:special, @special_example_group) + ExampleGroupFactory.register(:special_child, @special_child_example_group) + ExampleGroupFactory.register(:non_special, @nonspecial_example_group) + @example_group = @special_child_example_group.describe "Special Example Group" + @unselected_example_group = Class.new(@nonspecial_example_group).describe "Non Special Example Group" + end + + after(:each) do + ExampleGroupFactory.reset + end + + describe "#prepend_before" do + it "prepends the before block on all instances of the passed in type" do + order = [] + @config.prepend_before(:all) do + order << :prepend__before_all + end + @config.prepend_before(:all, :type => :special) do + order << :special_prepend__before_all + end + @config.prepend_before(:all, :type => :special_child) do + order << :special_child_prepend__before_all + end + @config.prepend_before(:each) do + order << :prepend__before_each + end + @config.prepend_before(:each, :type => :special) do + order << :special_prepend__before_each + end + @config.prepend_before(:each, :type => :special_child) do + order << :special_child_prepend__before_each + end + @config.prepend_before(:all, :type => :non_special) do + order << :special_prepend__before_all + end + @config.prepend_before(:each, :type => :non_special) do + order << :special_prepend__before_each + end + @example_group.it "calls prepend_before" do + end + + @example_group.run + order.should == [ + :prepend__before_all, + :special_prepend__before_all, + :special_child_prepend__before_all, + :prepend__before_each, + :special_prepend__before_each, + :special_child_prepend__before_each + ] + end + end + + describe "#append_before" do + + it "calls append_before on the type" do + order = [] + @config.append_before(:all) do + order << :append_before_all + end + @config.append_before(:all, :type => :special) do + order << :special_append_before_all + end + @config.append_before(:all, :type => :special_child) do + order << :special_child_append_before_all + end + @config.append_before(:each) do + order << :append_before_each + end + @config.append_before(:each, :type => :special) do + order << :special_append_before_each + end + @config.append_before(:each, :type => :special_child) do + order << :special_child_append_before_each + end + @config.append_before(:all, :type => :non_special) do + order << :special_append_before_all + end + @config.append_before(:each, :type => :non_special) do + order << :special_append_before_each + end + @example_group.it "calls append_before" do + end + + @example_group.run + order.should == [ + :append_before_all, + :special_append_before_all, + :special_child_append_before_all, + :append_before_each, + :special_append_before_each, + :special_child_append_before_each + ] + end + end + + describe "#prepend_after" do + + it "prepends the after block on all instances of the passed in type" do + order = [] + @config.prepend_after(:all) do + order << :prepend__after_all + end + @config.prepend_after(:all, :type => :special) do + order << :special_prepend__after_all + end + @config.prepend_after(:all, :type => :special) do + order << :special_child_prepend__after_all + end + @config.prepend_after(:each) do + order << :prepend__after_each + end + @config.prepend_after(:each, :type => :special) do + order << :special_prepend__after_each + end + @config.prepend_after(:each, :type => :special) do + order << :special_child_prepend__after_each + end + @config.prepend_after(:all, :type => :non_special) do + order << :special_prepend__after_all + end + @config.prepend_after(:each, :type => :non_special) do + order << :special_prepend__after_each + end + @example_group.it "calls prepend_after" do + end + + @example_group.run + order.should == [ + :special_child_prepend__after_each, + :special_prepend__after_each, + :prepend__after_each, + :special_child_prepend__after_all, + :special_prepend__after_all, + :prepend__after_all + ] + end + end + + describe "#append_after" do + + it "calls append_after on the type" do + order = [] + @config.append_after(:all) do + order << :append__after_all + end + @config.append_after(:all, :type => :special) do + order << :special_append__after_all + end + @config.append_after(:all, :type => :special_child) do + order << :special_child_append__after_all + end + @config.append_after(:each) do + order << :append__after_each + end + @config.append_after(:each, :type => :special) do + order << :special_append__after_each + end + @config.append_after(:each, :type => :special_child) do + order << :special_child_append__after_each + end + @config.append_after(:all, :type => :non_special) do + order << :non_special_append_after_all + end + @config.append_after(:each, :type => :non_special) do + order << :non_special_append_after_each + end + @example_group.it "calls append_after" do + end + + @example_group.run + order.should == [ + :special_child_append__after_each, + :special_append__after_each, + :append__after_each, + :special_child_append__after_all, + :special_append__after_all, + :append__after_all + ] + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/example_group_class_definition_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_group_class_definition_spec.rb new file mode 100644 index 000000000..0b00e1397 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_group_class_definition_spec.rb @@ -0,0 +1,48 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + class ExampleGroupSubclass < ExampleGroup + class << self + attr_accessor :examples_ran + end + + @@klass_variable_set = true + CONSTANT = :foobar + + before do + @instance_variable = :hello + end + + it "should run" do + self.class.examples_ran = true + end + + it "should have access to instance variables" do + @instance_variable.should == :hello + end + + it "should have access to class variables" do + @@klass_variable_set.should == true + end + + it "should have access to constants" do + CONSTANT.should == :foobar + end + + it "should have access to methods defined in the Example Group" do + a_method.should == 22 + end + + def a_method + 22 + end + end + + describe ExampleGroupSubclass do + it "should run" do + ExampleGroupSubclass.examples_ran.should be_true + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb new file mode 100644 index 000000000..3b50011f7 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb @@ -0,0 +1,129 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + describe ExampleGroupFactory, "with :foobar registered as custom type" do + + before do + @example_group = Class.new(ExampleGroup) + ExampleGroupFactory.register(:foobar, @example_group) + end + + after do + ExampleGroupFactory.reset + end + + it "should #get the default ExampleGroup type when passed nil" do + ExampleGroupFactory.get(nil).should == ExampleGroup + end + + it "should #get the default ExampleGroup for unregistered non-nil values" do + ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup + end + + it "should #get custom type for :foobar" do + ExampleGroupFactory.get(:foobar).should == @example_group + end + + it "should #get the actual type when that is passed in" do + ExampleGroupFactory.get(@example_group).should == @example_group + end + + end + + describe ExampleGroupFactory, "#create_example_group" do + it "should create a uniquely named class" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {} + example_group.name.should =~ /Spec::Example::ExampleGroup::Subclass_\d+/ + end + + it "should create a Spec::Example::Example subclass by default" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {} + example_group.superclass.should == Spec::Example::ExampleGroup + end + + it "should create a Spec::Example::Example when :type => :default" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "example_group", :type => :default + ) {} + example_group.superclass.should == Spec::Example::ExampleGroup + end + + it "should create a Spec::Example::Example when :type => :default" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "example_group", :type => :default + ) {} + example_group.superclass.should == Spec::Example::ExampleGroup + end + + it "should create specified type when :type => :something_other_than_default" do + klass = Class.new(ExampleGroup) do + def initialize(*args, &block); end + end + Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass) + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "example_group", :type => :something_other_than_default + ) {} + example_group.superclass.should == klass + end + + it "should create a type indicated by :spec_path" do + klass = Class.new(ExampleGroup) do + def initialize(*args, &block); end + end + Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass) + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "example_group", :spec_path => "./spec/something_other_than_default/some_spec.rb" + ) {} + example_group.superclass.should == klass + end + + it "should create a type indicated by :spec_path (with spec_path generated by caller on windows)" do + klass = Class.new(ExampleGroup) do + def initialize(*args, &block); end + end + Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass) + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "example_group", :spec_path => "./spec\\something_other_than_default\\some_spec.rb" + ) {} + example_group.superclass.should == klass + end + + it "should create and register a Spec::Example::Example if :shared => true" do + shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true + ) {} + shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup) + SharedExampleGroup.shared_example_groups.should include(shared_example_group) + end + + it "should favor the :type over the :spec_path" do + klass = Class.new(ExampleGroup) do + def initialize(*args, &block); end + end + Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass) + example_group = Spec::Example::ExampleGroupFactory.create_example_group( + "name", :spec_path => '/blah/spec/models/blah.rb', :type => :something_other_than_default + ) {} + example_group.superclass.should == klass + end + + it "should register ExampleGroup by default" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do + end + rspec_options.example_groups.should include(example_group) + end + + it "should enable unregistering of ExampleGroups" do + example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do + unregister + end + rspec_options.example_groups.should_not include(example_group) + end + + after(:each) do + Spec::Example::ExampleGroupFactory.reset + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb new file mode 100644 index 000000000..fa08e6fca --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb @@ -0,0 +1,480 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + describe 'ExampleGroupMethods' do + it_should_behave_like "sandboxed rspec_options" + attr_reader :example_group, :result, :reporter + before(:each) do + options.formatters << mock("formatter", :null_object => true) + options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true) + @reporter = FakeReporter.new(@options) + options.reporter = reporter + @example_group = Class.new(ExampleGroup) do + describe("ExampleGroup") + it "does nothing" + end + class << example_group + public :include + end + @result = nil + end + + after(:each) do + ExampleGroup.reset + end + + describe "#describe" do + attr_reader :child_example_group + before do + @child_example_group = @example_group.describe("Another ExampleGroup") do + it "should pass" do + true.should be_true + end + end + end + + it "should create a subclass of the ExampleGroup when passed a block" do + child_example_group.superclass.should == @example_group + @options.example_groups.should include(child_example_group) + end + + it "should not inherit examples" do + child_example_group.examples.length.should == 1 + end + end + + describe "#it" do + it "should should create an example instance" do + lambda { + @example_group.it("") + }.should change { @example_group.examples.length }.by(1) + end + end + + describe "#xit" do + before(:each) do + Kernel.stub!(:warn) + end + + it "should NOT should create an example instance" do + lambda { + @example_group.xit("") + }.should_not change(@example_group.examples, :length) + end + + it "should warn that it is disabled" do + Kernel.should_receive(:warn).with("Example disabled: foo") + @example_group.xit("foo") + end + end + + describe "#examples" do + it "should have Examples" do + example_group = Class.new(ExampleGroup) do + describe('example') + it "should pass" do + 1.should == 1 + end + end + example_group.examples.length.should == 1 + example_group.examples.first.description.should == "should pass" + end + + it "should not include methods that begin with test (only when TU interop is loaded)" do + example_group = Class.new(ExampleGroup) do + describe('example') + def test_any_args(*args) + true.should be_true + end + def test_something + 1.should == 1 + end + def test + raise "This is not a real test" + end + def testify + raise "This is not a real test" + end + end + example_group.examples.length.should == 0 + example_group.run.should be_true + end + + it "should include methods that begin with should and has an arity of 0 in suite" do + example_group = Class.new(ExampleGroup) do + describe('example') + def shouldCamelCase + true.should be_true + end + def should_any_args(*args) + true.should be_true + end + def should_something + 1.should == 1 + end + def should_not_something + 1.should_not == 2 + end + def should + raise "This is not a real example" + end + def should_not + raise "This is not a real example" + end + end + example_group = example_group.dup + example_group.examples.length.should == 4 + descriptions = example_group.examples.collect {|example| example.description}.sort + descriptions.should include("shouldCamelCase") + descriptions.should include("should_any_args") + descriptions.should include("should_something") + descriptions.should include("should_not_something") + end + + it "should not include methods that begin with test_ and has an arity > 0 in suite" do + example_group = Class.new(ExampleGroup) do + describe('example') + def test_invalid(foo) + 1.should == 1 + end + def testInvalidCamelCase(foo) + 1.should == 1 + end + end + example_group.examples.length.should == 0 + end + + it "should not include methods that begin with should_ and has an arity > 0 in suite" do + example_group = Class.new(ExampleGroup) do + describe('example') + def should_invalid(foo) + 1.should == 2 + end + def shouldInvalidCamelCase(foo) + 1.should == 3 + end + def should_not_invalid(foo) + 1.should == 4 + end + def should_valid + 1.should == 1 + end + end + example_group.examples.length.should == 1 + example_group.run.should be_true + end + + it "should run should_methods" do + example_group = Class.new(ExampleGroup) do + def should_valid + 1.should == 2 + end + end + example_group.examples.length.should == 1 + example_group.run.should be_false + end + end + + describe "#set_description" do + attr_reader :example_group + before do + class << example_group + public :set_description + end + end + + describe "#set_description(String)" do + before(:each) do + example_group.set_description("abc") + end + + specify ".description should return the String passed into .set_description" do + example_group.description.should == "abc" + end + + specify ".described_type should provide nil as its type" do + example_group.described_type.should be_nil + end + end + + describe "#set_description(Type)" do + before(:each) do + example_group.set_description(ExampleGroup) + end + + specify ".description should return a String representation of that type (fully qualified) as its name" do + example_group.description.should == "Spec::Example::ExampleGroup" + end + + specify ".described_type should return the passed in type" do + example_group.described_type.should == Spec::Example::ExampleGroup + end + end + + describe "#set_description(String, Type)" do + before(:each) do + example_group.set_description("behaving", ExampleGroup) + end + + specify ".description should return String then space then Type" do + example_group.description.should == "behaving Spec::Example::ExampleGroup" + end + + specify ".described_type should return the passed in type" do + example_group.described_type.should == Spec::Example::ExampleGroup + end + end + + describe "#set_description(Type, String not starting with a space)" do + before(:each) do + example_group.set_description(ExampleGroup, "behaving") + end + + specify ".description should return the Type then space then String" do + example_group.description.should == "Spec::Example::ExampleGroup behaving" + end + end + + describe "#set_description(Type, String starting with .)" do + before(:each) do + example_group.set_description(ExampleGroup, ".behaving") + end + + specify ".description should return the Type then String" do + example_group.description.should == "Spec::Example::ExampleGroup.behaving" + end + end + + describe "#set_description(Type, String containing .)" do + before(:each) do + example_group.set_description(ExampleGroup, "calling a.b") + end + + specify ".description should return the Type then space then String" do + example_group.description.should == "Spec::Example::ExampleGroup calling a.b" + end + end + + describe "#set_description(Type, String starting with .)" do + before(:each) do + example_group.set_description(ExampleGroup, ".behaving") + end + + specify "should return the Type then String" do + example_group.description.should == "Spec::Example::ExampleGroup.behaving" + end + end + + describe "#set_description(Type, String containing .)" do + before(:each) do + example_group.set_description(ExampleGroup, "is #1") + end + + specify ".description should return the Type then space then String" do + example_group.description.should == "Spec::Example::ExampleGroup is #1" + end + end + + describe "#set_description(String, Type, String)" do + before(:each) do + example_group.set_description("A", Hash, "with one entry") + end + + specify ".description should return the first String then space then Type then second String" do + example_group.description.should == "A Hash with one entry" + end + end + + describe "#set_description(Hash representing options)" do + before(:each) do + example_group.set_description(:a => "b", :spec_path => "blah") + end + + it ".spec_path should expand the passed in :spec_path option passed into the constructor" do + example_group.spec_path.should == File.expand_path("blah") + end + + it ".description_options should return all the options passed in" do + example_group.description_options.should == {:a => "b", :spec_path => "blah"} + end + + end + end + + describe "#description" do + it "should return the same description instance for each call" do + example_group.description.should eql(example_group.description) + end + + it "should not add a space when description_text begins with #" do + child_example_group = Class.new(example_group) do + describe("#foobar", "Does something") + end + child_example_group.description.should == "ExampleGroup#foobar Does something" + end + + it "should not add a space when description_text begins with ." do + child_example_group = Class.new(example_group) do + describe(".foobar", "Does something") + end + child_example_group.description.should == "ExampleGroup.foobar Does something" + end + + it "should return the class name if nil" do + example_group.set_description(nil) + example_group.description.should =~ /Class:/ + end + + it "should return the class name if nil" do + example_group.set_description("") + example_group.description.should =~ /Class:/ + end + end + + describe "#description_parts" do + it "should return an Array of the current class description args" do + example_group.description_parts.should == [example_group.description] + end + + it "should return an Array of the description args from each class in the hierarchy" do + child_example_group = Class.new(example_group) + child_example_group.describe("Child", ExampleGroup) + child_example_group.description.should_not be_empty + + grand_child_example_group = Class.new(child_example_group) + grand_child_example_group.describe("GrandChild", ExampleGroup) + grand_child_example_group.description.should_not be_empty + + grand_child_example_group.description_parts.should == [ + "ExampleGroup", + "Child", + Spec::Example::ExampleGroup, + "GrandChild", + Spec::Example::ExampleGroup + ] + end + end + + describe "#described_type" do + it "should return passed in type" do + child_example_group = Class.new(example_group) do + describe Object + end + child_example_group.described_type.should == Object + end + + it "should return #described_type of superclass when no passed in type" do + parent_example_group = Class.new(ExampleGroup) do + describe Object, "#foobar" + end + child_example_group = Class.new(parent_example_group) do + describe "not a type" + end + child_example_group.described_type.should == Object + end + end + + describe "#remove_after" do + it "should unregister a given after(:each) block" do + after_all_ran = false + @example_group.it("example") {} + proc = Proc.new { after_all_ran = true } + ExampleGroup.after(:each, &proc) + @example_group.run + after_all_ran.should be_true + + after_all_ran = false + ExampleGroup.remove_after(:each, &proc) + @example_group.run + after_all_ran.should be_false + end + end + + describe "#include" do + it "should have accessible class methods from included module" do + mod1_method_called = false + mod1 = Module.new do + class_methods = Module.new do + define_method :mod1_method do + mod1_method_called = true + end + end + + metaclass.class_eval do + define_method(:included) do |receiver| + receiver.extend class_methods + end + end + end + + mod2_method_called = false + mod2 = Module.new do + class_methods = Module.new do + define_method :mod2_method do + mod2_method_called = true + end + end + + metaclass.class_eval do + define_method(:included) do |receiver| + receiver.extend class_methods + end + end + end + + @example_group.include mod1, mod2 + + @example_group.mod1_method + @example_group.mod2_method + mod1_method_called.should be_true + mod2_method_called.should be_true + end + end + + describe "#number_of_examples" do + it "should count number of specs" do + proc do + @example_group.it("one") {} + @example_group.it("two") {} + @example_group.it("three") {} + @example_group.it("four") {} + end.should change {@example_group.number_of_examples}.by(4) + end + end + + describe "#class_eval" do + it "should allow constants to be defined" do + example_group = Class.new(ExampleGroup) do + describe('example') + FOO = 1 + it "should reference FOO" do + FOO.should == 1 + end + end + example_group.run + Object.const_defined?(:FOO).should == false + end + end + + describe '#register' do + it "should add ExampleGroup to set of ExampleGroups to be run" do + example_group.register + options.example_groups.should include(example_group) + end + end + + describe '#unregister' do + before do + example_group.register + options.example_groups.should include(example_group) + end + + it "should remove ExampleGroup from set of ExampleGroups to be run" do + example_group.unregister + options.example_groups.should_not include(example_group) + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb new file mode 100644 index 000000000..93e558a97 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_group_spec.rb @@ -0,0 +1,711 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + class ExampleModuleScopingSpec < ExampleGroup + describe ExampleGroup, "via a class definition" + + module Foo + module Bar + def self.loaded? + true + end + end + end + include Foo + + it "should understand module scoping" do + Bar.should be_loaded + end + + @@foo = 1 + + it "should allow class variables to be defined" do + @@foo.should == 1 + 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 + end.should raise_error + end + end + + describe ExampleGroup, "#pending" do + it "should raise a Pending error when its block fails" do + block_ran = false + lambda { + pending("something") do + block_ran = true + raise "something wrong with my example" + end + }.should raise_error(Spec::Example::ExamplePendingError, "something") + block_ran.should == true + end + + it "should raise Spec::Example::PendingExampleFixedError when its block does not fail" do + block_ran = false + lambda { + pending("something") do + block_ran = true + end + }.should raise_error(Spec::Example::PendingExampleFixedError, "Expected pending 'something' to fail. No Error was raised.") + block_ran.should == true + end + end + + describe ExampleGroup, "#run with failure in example", :shared => true do + it "should add an example failure to the TestResult" do + example_group.run.should be_false + end + 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 + 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") + end + example_group.run + end + end + + describe ExampleGroup, "#run on dry run" do + before do + @options.dry_run = true + 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 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 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' + end + + it("should also be run") do + examples_that_were_run << 'should also be run' + end + end + options.examples = ["the ExampleGroup"] + end + + 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 + + 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 + + it "should not run the example" do + 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 + 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 not run the example" do + example_group.run + examples_that_were_run.should == [] + end + 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 only the example, when there in only one" do + example_group.run + examples_that_were_run.should == ["should be run"] + 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 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 + + after do + ExampleGroupFactory.reset + end + + it "should send reporter add_example_group" do + example_group.run + reporter.example_groups.should == [example_group] + 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 + + 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 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 "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 + + 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 + + it "should not add global before callbacks for untargetted example_group" do + fiddle = [] + + 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)" } + + 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 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 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 + + mod2_method_called = false + mod2 = Module.new do + define_method :mod2_method do + mod2_method_called = true + end + end + + 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 + + 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(@special_example_group).describe("I'm special", :type => :special) do + it "does nothing" + 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) + 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 + end + 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 + + $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 + 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 + + 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 + example_group.it("should be pending") do + pending("Example passes") {true.should be_true} + 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 + end + end + + describe ExampleGroup, "#run when before(:all) fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + + before do + ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" } + 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 + 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 + + 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 + + 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 + + example_group.it("test") {true} + example_group.run + end + end + + describe ExampleGroup, "#run when before(:each) fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + + 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 + end + end + + describe ExampleGroup, "#run when any example fails" do + it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example" + + before do + example_group.it("should") { 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 + end + end + + describe ExampleGroup, "#run when first after(: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 + + 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 + + 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 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 + end + + 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 + + it "should return false" do + example_group.run.should be_false + 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.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" + end + end + + describe Enumerable do + 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 + 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 + 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 diff --git a/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb new file mode 100644 index 000000000..ea0dfe019 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_matcher_spec.rb @@ -0,0 +1,96 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +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 + def match_description(description) + MatchDescription.new(description) + end + end + + describe ExampleMatcher, "#matches?" do + include ExampleMatcherSpecHelper + + it "should match correct example_group and example" do + matcher = ExampleMatcher.new("example_group", "example") + matcher.should match_description("example_group example") + end + + it "should not match wrong example" do + matcher = ExampleMatcher.new("example_group", "other example") + matcher.should_not match_description("example_group example") + end + + it "should not match wrong example_group" do + matcher = ExampleMatcher.new("other example_group", "example") + matcher.should_not match_description("example_group example") + end + + it "should match example only" do + matcher = ExampleMatcher.new("example_group", "example") + matcher.should match_description("example") + end + + it "should match example_group only" do + matcher = ExampleMatcher.new("example_group", "example") + matcher.should match_description("example_group") + end + + it "should match example_group ending with before(:all)" do + matcher = ExampleMatcher.new("example_group", "example") + matcher.should match_description("example_group before(:all)") + end + + it "should escape regexp chars" do + matcher = ExampleMatcher.new("(con|text)", "[example]") + matcher.should_not match_description("con p") + end + + it "should match when example_group is modularized" do + matcher = ExampleMatcher.new("MyModule::MyClass", "example") + matcher.should match_description("MyClass example") + end + end + + describe ExampleMatcher, "#matches? normal case" do + it "matches when passed in example matches" do + matcher = ExampleMatcher.new("Foo", "bar") + matcher.matches?(["no match", "Foo bar"]).should == true + end + + it "does not match when no passed in examples match" do + matcher = ExampleMatcher.new("Foo", "bar") + matcher.matches?(["no match1", "no match2"]).should == false + end + end + + describe ExampleMatcher, "#matches? where description has '::' in it" do + it "matches when passed in example matches" do + matcher = ExampleMatcher.new("Foo::Bar", "baz") + matcher.matches?(["no match", "Foo::Bar baz"]).should == true + end + + it "does not match when no passed in examples match" do + matcher = ExampleMatcher.new("Foo::Bar", "baz") + matcher.matches?(["no match1", "no match2"]).should == false + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb new file mode 100644 index 000000000..ce688a7f9 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_methods_spec.rb @@ -0,0 +1,91 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + module ModuleThatIsReopened + end + + module ExampleMethods + include ModuleThatIsReopened + end + + module ModuleThatIsReopened + def module_that_is_reopened_method + end + end + + describe "ExampleMethods with an included module that is reopened" do + it "should have repoened methods" do + method(:module_that_is_reopened_method).should_not be_nil + end + end + + describe ExampleMethods, "lifecycle" do + before do + @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new) + @options.formatters << mock("formatter", :null_object => true) + @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true) + @reporter = FakeReporter.new(@options) + @options.reporter = @reporter + + 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 + end + end + + after do + 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 + ExampleMethods.before(:all) do + ExampleMethods.count.should == 1 + end + + ExampleMethods.before(:each) do + ExampleMethods.count.should == 2 + end + + ExampleMethods.after(:each) do + ExampleMethods.count.should == 3 + end + + ExampleMethods.after(:all) do + ExampleMethods.count.should == 4 + end + + @example_group = Class.new(ExampleGroup) do + it "should use ExampleMethods callbacks" do + end + end + @example_group.run + ExampleMethods.count.should == 5 + end + + describe "run_with_description_capturing" 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 + end + + it "should provide the generated description" do + @example.instance_eval { @_matcher_description }.should == "should == 2" + end + + it "should clear the global generated_description" do + Spec::Matchers.generated_description.should == nil + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/example/example_runner_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_runner_spec.rb new file mode 100644 index 000000000..1b5abdf0f --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_runner_spec.rb @@ -0,0 +1,194 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Example + # describe "Spec::Example::ExampleRunner", "#run", :shared => true do + # before(:each) do + # @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new) + # @reporter = ::Spec::Runner::Reporter.new(@options) + # @options.reporter = @reporter + # @example_group_class = Class.new(ExampleGroup) do + # plugin_mock_framework + # describe("Some Examples") + # end + # end + # + # def create_runner(example_definition) + # example = @example_group_class.new(example_definition) + # runner = ExampleGroup.new(@options, example) + # runner.stub!(:verify_mocks) + # runner.stub!(:teardown_mocks) + # runner + # end + # end + # + # describe ExampleRunner, "#run with blank passing example" do + # it_should_behave_like "Spec::Example::ExampleRunner#run" + # + # before do + # @e = @example_group_class.it("example") {} + # @runner = create_runner(@e) + # end + # + # it "should send reporter example_started" do + # @reporter.should_receive(:example_started).with(equal(@e)) + # @runner.run + # end + # + # it "should report its name for dry run" do + # @options.dry_run = true + # @reporter.should_receive(:example_finished).with(equal(@e), nil) + # @runner.run + # end + # + # it "should report success" do + # @reporter.should_receive(:example_finished).with(equal(@e), nil) + # @runner.run + # end + # end + # + # describe ExampleRunner, "#run with a failing example" do + # predicate_matchers[:is_a] = [:is_a?] + # it_should_behave_like "Spec::Example::ExampleRunner#run" + # + # before do + # @e = @example_group_class.it("example") do + # (2+2).should == 5 + # end + # @runner = create_runner(@e) + # end + # + # it "should report failure due to failure" do + # @reporter.should_receive(:example_finished).with( + # equal(@e), + # is_a(Spec::Expectations::ExpectationNotMetError) + # ) + # @runner.run + # end + # end + # + # describe ExampleRunner, "#run with a erroring example" do + # it_should_behave_like "Spec::Example::ExampleRunner#run" + # + # before do + # @error = error = NonStandardError.new("in body") + # @example_definition = @example_group_class.it("example") do + # raise(error) + # end + # @runner = create_runner(@example_definition) + # end + # + # it "should report failure due to error" do + # @reporter.should_receive(:example_finished).with( + # equal(@example_definition), + # @error + # ) + # @runner.run + # end + # + # it "should run after_each block" do + # @example_group_class.after(:each) do + # raise("in after_each") + # end + # @reporter.should_receive(:example_finished) do |example_definition, error| + # example_definition.should equal(@example_definition) + # error.message.should eql("in body") + # end + # @runner.run + # end + # end + # + # describe ExampleRunner, "#run where after_each fails" do + # it_should_behave_like "Spec::Example::ExampleRunner#run" + # + # before do + # @example_ran = example_ran = false + # @example_definition = @example_group_class.it("should not run") do + # example_ran = true + # end + # @runner = create_runner(@example_definition) + # @example_group_class.after(:each) { raise(NonStandardError.new("in after_each")) } + # end + # + # it "should report failure location when in after_each" do + # @reporter.should_receive(:example_finished) do |example_definition, error| + # example_definition.should equal(@example_definition) + # error.message.should eql("in after_each") + # end + # @runner.run + # end + # end + # + # describe ExampleRunner, "#run with use cases" do + # predicate_matchers[:is_a] = [:is_a?] + # it_should_behave_like "Spec::Example::ExampleRunner#run" + # + # it "should report NO NAME when told to use generated description with --dry-run" do + # @options.dry_run = true + # example_definition = @example_group_class.it() do + # 5.should == 5 + # end + # runner = create_runner(example_definition) + # + # @reporter.should_receive(:example_finished) do |example_definition, error| + # example_definition.description.should == "NO NAME (Because of --dry-run)" + # end + # runner.run + # end + # + # it "should report given name if present with --dry-run" do + # @options.dry_run = true + # example_definition = @example_group_class.it("example name") do + # 5.should == 5 + # end + # runner = create_runner(example_definition) + # + # @reporter.should_receive(:example_finished) do |example_definition, error| + # example_definition.description.should == "example name" + # end + # runner.run + # end + # + # it "should report NO NAME when told to use generated description with no expectations" do + # example_definition = @example_group_class.it() {} + # runner = create_runner(example_definition) + # @reporter.should_receive(:example_finished) do |example, error| + # example.description.should == "NO NAME (Because there were no expectations)" + # end + # runner.run + # end + # + # it "should report NO NAME when told to use generated description and matcher fails" do + # example_definition = @example_group_class.it() do + # 5.should "" # Has no matches? method.. + # end + # runner = create_runner(example_definition) + # + # @reporter.should_receive(:example_finished) do |example, error| + # example_definition.description.should == "NO NAME (Because of Error raised in matcher)" + # end + # runner.run + # end + # + # it "should report generated description when told to and it is available" do + # example_definition = @example_group_class.it() { + # 5.should == 5 + # } + # runner = create_runner(example_definition) + # + # @reporter.should_receive(:example_finished) do |example_definition, error| + # example_definition.description.should == "should == 5" + # end + # runner.run + # end + # + # it "should unregister description_generated callback (lest a memory leak should build up)" do + # example_definition = @example_group_class.it("something") + # runner = create_runner(example_definition) + # + # Spec::Matchers.should_receive(:example_finished) + # runner.run + # end + # end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/example_spec.rb b/vendor/plugins/rspec/spec/spec/example/example_spec.rb new file mode 100644 index 000000000..c8125b447 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/example_spec.rb @@ -0,0 +1,53 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + # describe Example do + # before(:each) do + # @example = Example.new "example" do + # foo + # end + # end + # + # it "should tell you its docstring" do + # @example.description.should == "example" + # end + # + # it "should execute its block in the context provided" do + # context = Class.new do + # def foo + # "foo" + # end + # end.new + # @example.run_in(context).should == "foo" + # end + # end + # + # describe Example, "#description" do + # it "should default to NO NAME when not passed anything when there are no matchers" do + # example = Example.new {} + # example.run_in(Object.new) + # example.description.should == "NO NAME" + # end + # + # it "should default to NO NAME description (Because of --dry-run) when passed nil and there are no matchers" do + # example = Example.new(nil) {} + # example.run_in(Object.new) + # example.description.should == "NO NAME" + # end + # + # it "should allow description to be overridden" do + # example = Example.new("Test description") + # example.description.should == "Test description" + # end + # + # it "should use description generated from matcher when there is no passed in description" do + # example = Example.new(nil) do + # 1.should == 1 + # end + # example.run_in(Object.new) + # example.description.should == "should == 1" + # end + # end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/nested_example_group_spec.rb b/vendor/plugins/rspec/spec/spec/example/nested_example_group_spec.rb new file mode 100644 index 000000000..35e8a9890 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/nested_example_group_spec.rb @@ -0,0 +1,59 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + describe 'Nested Example Groups' do + parent = self + + def count + @count ||= 0 + @count = @count + 1 + @count + end + + before(:all) do + count.should == 1 + end + + before(:all) do + count.should == 2 + end + + before(:each) do + count.should == 3 + end + + before(:each) do + count.should == 4 + end + + it "should run before(:all), before(:each), example, after(:each), after(:all) in order" do + count.should == 5 + end + + after(:each) do + count.should == 7 + end + + after(:each) do + count.should == 6 + end + + after(:all) do + count.should == 9 + end + + after(:all) do + count.should == 8 + end + + describe 'nested example group' do + self.superclass.should == parent + + it "should run all before and after callbacks" do + count.should == 5 + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb b/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb new file mode 100644 index 000000000..c3ab0126b --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/pending_module_spec.rb @@ -0,0 +1,31 @@ +module Spec + module Example + describe Pending do + + 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 a PendingExampleFixedError if a supplied block starts working' do + lambda { + include Pending + pending "TODO" do + # success! + end + }.should raise_error(PendingExampleFixedError, /TODO/) + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/predicate_matcher_spec.rb b/vendor/plugins/rspec/spec/spec/example/predicate_matcher_spec.rb new file mode 100644 index 000000000..7c4638b4b --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/predicate_matcher_spec.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + class Fish + def can_swim?(distance_in_yards) + distance_in_yards < 1000 + end + end + + describe "predicate_matcher[method_on_object] = matcher_method" do + predicate_matchers[:swim] = :can_swim? + it "should match matcher_method if method_on_object returns true" do + swim(100).matches?(Fish.new).should be_true + end + it "should not match matcher_method if method_on_object returns false" do + swim(10000).matches?(Fish.new).should be_false + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb b/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb new file mode 100644 index 000000000..803536ab5 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/shared_example_group_spec.rb @@ -0,0 +1,265 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +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 + 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 + + it "should complain when adding a second shared example_group with the same description" do + describe "shared example_group", :shared => true do + end + lambda 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 + + 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 + end + 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" + ) + + SharedExampleGroup.add_shared_example_group(shared_example_group_1) + SharedExampleGroup.add_shared_example_group(shared_example_group_2) + 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 + + 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") {} + 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 + + 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 + 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 } + 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 "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 + + 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 + + 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 = make_shared_example_group("shared example_group") do + it("shared example") { shared_example_ran = true } + end + + 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 + + shared_example_group.include mod2 + + example_group.it_should_behave_like("shared example_group") + example_group.include mod1 + + 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 + + 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" + 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 + + 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 diff --git a/vendor/plugins/rspec/spec/spec/example/subclassing_example_group_spec.rb b/vendor/plugins/rspec/spec/spec/example/subclassing_example_group_spec.rb new file mode 100644 index 000000000..888f2ceb3 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/example/subclassing_example_group_spec.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Example + class GrandParentExampleGroup < Spec::Example::ExampleGroup + describe "Grandparent ExampleGroup" + end + + class ParentExampleGroup < GrandParentExampleGroup + describe "Parent ExampleGroup" + it "should bar" do + end + end + + class ChildExampleGroup < ParentExampleGroup + describe "Child ExampleGroup" + it "should bam" do + end + end + + describe ChildExampleGroup do + + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/extensions/main_spec.rb b/vendor/plugins/rspec/spec/spec/extensions/main_spec.rb new file mode 100644 index 000000000..aabb616e9 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/extensions/main_spec.rb @@ -0,0 +1,76 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Extensions + describe Main do + it_should_behave_like "sandboxed rspec_options" + before(:each) do + @main = Class.new do; include Main; end + end + + after(:each) do + $rspec_story_steps = @original_rspec_story_steps + end + + it "should create an Options object" do + @main.send(:rspec_options).should be_instance_of(Spec::Runner::Options) + @main.send(:rspec_options).should === $rspec_options + end + + specify {@main.should respond_to(:describe)} + specify {@main.should respond_to(:context)} + + it "should raise when no block given to describe" do + lambda { @main.describe "foo" }.should raise_error(ArgumentError) + end + + it "should raise when no description given to describe" do + lambda { @main.describe do; end }.should raise_error(ArgumentError) + end + + it "should registered ExampleGroups by default" do + example_group = @main.describe("The ExampleGroup") do end + rspec_options.example_groups.should include(example_group) + end + + it "should not run unregistered ExampleGroups" do + example_group = @main.describe("The ExampleGroup") do + unregister + end + + rspec_options.example_groups.should_not include(example_group) + end + + it "should create a shared ExampleGroup with share_examples_for" do + group = @main.share_examples_for "all things" do end + group.should be_an_instance_of(Spec::Example::SharedExampleGroup) + end + + describe "#share_as" do + before(:each) do + $share_as_examples_example_module_number ||= 1 + $share_as_examples_example_module_number += 1 + t = Time.new.to_i + @group_name = "Group#{$share_as_examples_example_module_number}" + end + + it "should create a shared ExampleGroup" do + group = @main.share_as @group_name do end + group.should be_an_instance_of(Spec::Example::SharedExampleGroup) + end + + it "should create a constant that points to a Module" do + group = @main.share_as @group_name do end + Object.const_get(@group_name).should equal(group) + end + + it "should bark if you pass it something not-constantizable" do + lambda do + @group = @main.share_as "Non Constant" do end + end.should raise_error(NameError, /The first argument to share_as must be a legal name for a constant/) + end + + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb b/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb new file mode 100644 index 000000000..04d5d2713 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/interop/test/unit/test_unit_spec_helper.rb @@ -0,0 +1,14 @@ +require File.dirname(__FILE__) + '/../../../../spec_helper' +require File.dirname(__FILE__) + '/../../../../ruby_forker' + +module TestUnitSpecHelper + include RubyForker + + def run_script(file_name) + output = ruby(file_name) + if !$?.success? || output.include?("FAILED") || output.include?("Error") + raise output + end + output + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb b/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb new file mode 100644 index 000000000..3e10ba7b5 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/test_unit_spec_helper' + +describe "Test::Unit::TestCase" do + include TestUnitSpecHelper + it "should pass" do + dir = File.dirname(__FILE__) + output = run_script("#{dir}/testcase_spec_with_test_unit.rb") + output.should include("3 examples, 0 failures") + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec_with_test_unit.rb b/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec_with_test_unit.rb new file mode 100644 index 000000000..52afd8e4c --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/interop/test/unit/testcase_spec_with_test_unit.rb @@ -0,0 +1,20 @@ +require "test/unit" +require File.dirname(__FILE__) + '/../../../../spec_helper.rb' + +describe "TestCase#method_name" do + it "should equal the description of the example" do + @method_name.should == "should equal the description of the example" + end + + def test_this + true.should be_true + end + + def testThis + true.should be_true + end + + def testament + raise "testament is not a test" + end +end diff --git a/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec.rb b/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec.rb new file mode 100644 index 000000000..bcb25b36c --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec.rb @@ -0,0 +1,9 @@ +require File.dirname(__FILE__) + '/test_unit_spec_helper' + +describe "TestSuiteAdapter" do + include TestUnitSpecHelper + it "should pass" do + dir = File.dirname(__FILE__) + run_script "#{dir}/testsuite_adapter_spec_with_test_unit.rb" + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec_with_test_unit.rb b/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec_with_test_unit.rb new file mode 100644 index 000000000..8088ef50e --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/interop/test/unit/testsuite_adapter_spec_with_test_unit.rb @@ -0,0 +1,34 @@ +require "test/unit" +require File.dirname(__FILE__) + '/../../../../spec_helper.rb' + +module TestSuiteAdapterSpecHelper + def create_adapter(group) + Test::Unit::TestSuiteAdapter.new(group) + end +end + +describe "TestSuiteAdapter#size" do + include TestSuiteAdapterSpecHelper + it "should return the number of examples in the example group" do + group = Class.new(Spec::ExampleGroup) do + describe("some examples") + it("bar") {} + it("baz") {} + end + adapter = create_adapter(group) + adapter.size.should == 2 + end +end + +describe "TestSuiteAdapter#delete" do + include TestSuiteAdapterSpecHelper + it "should do nothing" do + group = Class.new(Spec::ExampleGroup) do + describe("Some Examples") + it("does something") {} + end + adapter = create_adapter(group) + adapter.delete(adapter.examples.first) + adapter.should be_empty + end +end diff --git a/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb b/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb new file mode 100644 index 000000000..b731af92d --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/matchers/simple_matcher_spec.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +module Spec + module Matchers + describe SimpleMatcher do + it "should match pass match arg to block" do + actual = nil + matcher = simple_matcher("message") do |given| actual = given end + matcher.matches?("foo") + actual.should == "foo" + end + + it "should provide a stock failure message" do + matcher = simple_matcher("thing") do end + matcher.matches?("other") + matcher.failure_message.should =~ /expected \"thing\" but got \"other\"/ + end + + it "should provide a stock negative failure message" do + matcher = simple_matcher("thing") do end + matcher.matches?("other") + matcher.negative_failure_message.should =~ /expected not to get \"thing\", but got \"other\"/ + end + + it "should provide a description" do + matcher = simple_matcher("thing") do end + matcher.description.should =="thing" + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/mocks/bug_report_10263.rb b/vendor/plugins/rspec/spec/spec/mocks/bug_report_10263.rb new file mode 100644 index 000000000..f82180c09 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/mocks/bug_report_10263.rb @@ -0,0 +1,24 @@ +describe "Mock" do + before do + @mock = mock("test mock") + end + + specify "when one example has an expectation (non-mock) inside the block passed to the mock" do + @mock.should_receive(:msg) do |b| + b.should be_true #this call exposes the problem + end + @mock.msg(false) rescue nil + end + + specify "then the next example should behave as expected instead of saying" do + @mock.should_receive(:foobar) + @mock.foobar + @mock.rspec_verify + begin + @mock.foobar + rescue => e + e.message.should == "Mock 'test mock' received unexpected message :foobar with (no args)" + end + end +end + diff --git a/vendor/plugins/rspec/spec/spec/mocks/bug_report_15719_spec.rb b/vendor/plugins/rspec/spec/spec/mocks/bug_report_15719_spec.rb new file mode 100644 index 000000000..82d49ea97 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/mocks/bug_report_15719_spec.rb @@ -0,0 +1,30 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Mocks + describe "mock failure" do + + it "should tell you when it receives the right message with the wrong args" do + m = mock("foo") + m.should_receive(:bar).with("message") + lambda { + m.bar("different message") + }.should raise_error(Spec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")}) + m.bar("message") # allows the spec to pass + end + + it "should tell you when it receives the right message with the wrong args if you stub the method" do + pending("fix bug 15719") + # NOTE - for whatever reason, if you use a the block style of pending here, + # rcov gets unhappy. Don't know why yet. + m = mock("foo") + m.stub!(:bar) + m.should_receive(:bar).with("message") + lambda { + m.bar("different message") + }.should raise_error(Spec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")}) + m.bar("message") # allows the spec to pass + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner/class_and_argument_parser_spec.rb b/vendor/plugins/rspec/spec/spec/runner/class_and_argument_parser_spec.rb new file mode 100644 index 000000000..b4e9e7f53 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/class_and_argument_parser_spec.rb @@ -0,0 +1,23 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Runner + describe ClassAndArgumentsParser, ".parse" do + + it "should use a single : to separate class names from arguments" do + ClassAndArgumentsParser.parse('Foo').should == ['Foo', nil] + ClassAndArgumentsParser.parse('Foo:arg').should == ['Foo', 'arg'] + ClassAndArgumentsParser.parse('Foo::Bar::Zap:arg').should == ['Foo::Bar::Zap', 'arg'] + ClassAndArgumentsParser.parse('Foo:arg1,arg2').should == ['Foo', 'arg1,arg2'] + ClassAndArgumentsParser.parse('Foo::Bar::Zap:arg1,arg2').should == ['Foo::Bar::Zap', 'arg1,arg2'] + ClassAndArgumentsParser.parse('Foo::Bar::Zap:drb://foo,drb://bar').should == ['Foo::Bar::Zap', 'drb://foo,drb://bar'] + end + + it "should raise an error when passed an empty string" do + lambda do + ClassAndArgumentsParser.parse('') + end.should raise_error("Couldn't parse \"\"") + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb b/vendor/plugins/rspec/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb new file mode 100644 index 000000000..a08b6e86d --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb @@ -0,0 +1,44 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'spec/runner/formatter/failing_example_groups_formatter' + +module Spec + module Runner + module Formatter + describe FailingExampleGroupsFormatter do + attr_reader :example_group, :formatter, :io + + before(:each) do + @io = StringIO.new + options = mock('options') + @formatter = FailingExampleGroupsFormatter.new(options, io) + @example_group = Class.new(::Spec::Example::ExampleGroup) + end + + it "should add example name for each failure" do + formatter.add_example_group(Class.new(ExampleGroup).describe("b 1")) + formatter.example_failed("e 1", nil, Reporter::Failure.new(nil, RuntimeError.new)) + formatter.add_example_group(Class.new(ExampleGroup).describe("b 2")) + formatter.example_failed("e 2", nil, Reporter::Failure.new(nil, RuntimeError.new)) + formatter.example_failed("e 3", nil, Reporter::Failure.new(nil, RuntimeError.new)) + io.string.should == "b 1\nb 2\n" + end + + it "should delimit ExampleGroup superclass descriptions with :" do + parent_example_group = Class.new(example_group).describe("Parent") + child_example_group = Class.new(parent_example_group).describe("#child_method") + grand_child_example_group = Class.new(child_example_group).describe("GrandChild") + + formatter.add_example_group(grand_child_example_group) + formatter.example_failed("failure", nil, Reporter::Failure.new(nil, RuntimeError.new)) + io.string.should == "Parent#child_method GrandChild\n" + end + + it "should remove druby url, which is used by Spec::Distributed" do + @formatter.add_example_group(Class.new(ExampleGroup).describe("something something (druby://99.99.99.99:99)")) + @formatter.example_failed("e 1", nil, Reporter::Failure.new(nil, RuntimeError.new)) + io.string.should == "something something\n" + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb b/vendor/plugins/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb new file mode 100644 index 000000000..981805411 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb @@ -0,0 +1,65 @@ +require File.dirname(__FILE__) + '/../../../spec_helper.rb' +require 'spec/runner/formatter/profile_formatter' + +module Spec + module Runner + module Formatter + describe ProfileFormatter do + attr_reader :io, :formatter + before(:each) do + @io = StringIO.new + options = mock('options') + options.stub!(:colour).and_return(true) + @formatter = ProfileFormatter.new(options, io) + end + + it "should print a heading" do + formatter.start(0) + io.string.should eql("Profiling enabled.\n") + end + + it "should record the current time when starting a new example" do + now = Time.now + Time.stub!(:now).and_return(now) + formatter.example_started('should foo') + formatter.instance_variable_get("@time").should == now + end + + it "should correctly record a passed example" do + now = Time.now + Time.stub!(:now).and_return(now) + parent_example_group = Class.new(ExampleGroup).describe('Parent') + child_example_group = Class.new(parent_example_group).describe('Child') + + formatter.add_example_group(child_example_group) + + formatter.example_started('when foo') + Time.stub!(:now).and_return(now+1) + formatter.example_passed(stub('foo', :description => 'i like ice cream')) + + formatter.start_dump + io.string.should include('Parent Child') + end + + it "should sort the results in descending order" do + formatter.instance_variable_set("@example_times", [['a', 'a', 0.1], ['b', 'b', 0.3], ['c', 'c', 0.2]]) + formatter.start_dump + formatter.instance_variable_get("@example_times").should == [ ['b', 'b', 0.3], ['c', 'c', 0.2], ['a', 'a', 0.1]] + end + + it "should print the top 10 results" do + example_group = Class.new(::Spec::Example::ExampleGroup).describe("ExampleGroup") + formatter.add_example_group(example_group) + formatter.instance_variable_set("@time", Time.now) + + 15.times do + formatter.example_passed(stub('foo', :description => 'i like ice cream')) + end + + io.should_receive(:print).exactly(10) + formatter.start_dump + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb b/vendor/plugins/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb new file mode 100644 index 000000000..e782254e2 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb @@ -0,0 +1,103 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'hpricot' # Needed to compare generated with wanted HTML +require 'spec/runner/formatter/text_mate_formatter' + +module Spec + module Runner + module Formatter + describe TextMateFormatter do + attr_reader :root, :suffix, :expected_file + before do + @root = File.expand_path(File.dirname(__FILE__) + '/../../../..') + @suffix = jruby? ? '-jruby' : '' + @expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html" + end + + def jruby? + PLATFORM == 'java' + end + + def produces_html_identical_to_manually_designed_document(opt) + root = File.expand_path(File.dirname(__FILE__) + '/../../../..') + + Dir.chdir(root) do + args = [ + 'failing_examples/mocking_example.rb', + 'failing_examples/diffing_spec.rb', + 'examples/pure/stubbing_example.rb', + 'examples/pure/pending_example.rb', + '--format', + 'textmate', + opt + ] + err = StringIO.new + out = StringIO.new + options = ::Spec::Runner::OptionParser.parse(args, err, out) + Spec::Runner::CommandLine.run(options) + + yield(out.string) + end + end + + # # Uncomment this spec temporarily in order to overwrite the expected with actual. + # # Use with care!!! + # describe TextMateFormatter, "functional spec file generator" do + # it "generates a new comparison file" do + # Dir.chdir(root) do + # args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/pure/stubbing_example.rb', 'examples/pure/pending_example.rb', '--format', 'textmate', '--diff'] + # err = StringIO.new + # out = StringIO.new + # Spec::Runner::CommandLine.run( + # ::Spec::Runner::OptionParser.parse(args, err, out) + # ) + # + # seconds = /\d+\.\d+ seconds/ + # html = out.string.gsub seconds, 'x seconds' + # + # File.open(expected_file, 'w') {|io| io.write(html)} + # end + # end + # end + + describe "functional spec using --diff" do + it "should produce HTML identical to the one we designed manually with --diff" do + produces_html_identical_to_manually_designed_document("--diff") do |html| + suffix = jruby? ? '-jruby' : '' + expected_file = File.dirname(__FILE__) + "/text_mate_formatted-#{::VERSION}#{suffix}.html" + unless File.file?(expected_file) + raise "There is no HTML file with expected content for this platform: #{expected_file}" + end + expected_html = File.read(expected_file) + + seconds = /\d+\.\d+ seconds/ + html.gsub! seconds, 'x seconds' + expected_html.gsub! seconds, 'x seconds' + + doc = Hpricot(html) + backtraces = doc.search("div.backtrace/a") + doc.search("div.backtrace").remove + + expected_doc = Hpricot(expected_html) + expected_doc.search("div.backtrace").remove + + doc.inner_html.should == expected_doc.inner_html + + backtraces.each do |backtrace_link| + backtrace_link[:href].should include("txmt://open?url=") + end + end + end + + end + + describe "functional spec using --dry-run" do + it "should produce HTML identical to the one we designed manually with --dry-run" do + produces_html_identical_to_manually_designed_document("--dry-run") do |html, expected_html| + html.should =~ /This was a dry-run/m + end + end + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/story/html_formatter_spec.rb b/vendor/plugins/rspec/spec/spec/runner/formatter/story/html_formatter_spec.rb new file mode 100644 index 000000000..37fb7c670 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/story/html_formatter_spec.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../../../../spec_helper.rb' +require 'spec/runner/formatter/story/html_formatter' + +module Spec + module Runner + module Formatter + module Story + describe HtmlFormatter do + before :each do + @out = StringIO.new + @options = mock('options') + @reporter = HtmlFormatter.new(@options, @out) + end + + it "should just be poked at" do + @reporter.run_started(1) + @reporter.story_started('story_title', 'narrative') + + @reporter.scenario_started('story_title', 'succeeded_scenario_name') + @reporter.step_succeeded('given', 'succeded_step', 'one', 'two') + @reporter.scenario_succeeded('story_title', 'succeeded_scenario_name') + + @reporter.scenario_started('story_title', 'pending_scenario_name') + @reporter.step_pending('when', 'pending_step', 'un', 'deux') + @reporter.scenario_pending('story_title', 'pending_scenario_name', 'not done') + + @reporter.scenario_started('story_title', 'failed_scenario_name') + @reporter.step_failed('then', 'failed_step', 'en', 'to') + @reporter.scenario_failed('story_title', 'failed_scenario_name', NameError.new('sup')) + + @reporter.scenario_started('story_title', 'scenario_with_given_scenario_name') + @reporter.found_scenario('given scenario', 'succeeded_scenario_name') + + @reporter.story_ended('story_title', 'narrative') + @reporter.run_ended + end + + it "should create spans for params" do + @reporter.step_succeeded('given', 'a $coloured $animal', 'brown', 'dog') + @out.string.should == " <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n" + end + + it 'should create spanes for params in regexp steps' do + @reporter.step_succeeded :given, /a (pink|blue) (.*)/, 'brown', 'dog' + @out.string.should == " <li class=\"passed\">Given a <span class=\"param\">brown</span> <span class=\"param\">dog</span></li>\n" + end + + it "should create a ul for collected_steps" do + @reporter.collected_steps(['Given a $coloured $animal', 'Given a $n legged eel']) + @out.string.should == (<<-EOF) + <ul id="stock_steps" style="display: none;"> + <li>Given a $coloured $animal</li> + <li>Given a $n legged eel</li> + </ul> +EOF + end + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb b/vendor/plugins/rspec/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb new file mode 100644 index 000000000..27e184b0f --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb @@ -0,0 +1,335 @@ +require File.dirname(__FILE__) + '/../../../../spec_helper.rb' +require 'spec/runner/formatter/story/plain_text_formatter' + +module Spec + module Runner + module Formatter + module Story + describe PlainTextFormatter do + before :each do + # given + @out = StringIO.new + @tweaker = mock('tweaker') + @tweaker.stub!(:tweak_backtrace) + @options = mock('options') + @options.stub!(:colour).and_return(false) + @options.stub!(:backtrace_tweaker).and_return(@tweaker) + @formatter = PlainTextFormatter.new(@options, @out) + end + + it 'should summarize the number of scenarios when the run ends' do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario2') + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario3') + @formatter.run_ended + + # then + @out.string.should include('3 scenarios') + end + + it 'should summarize the number of successful scenarios when the run ends' do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario2') + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario3') + @formatter.run_ended + + # then + @out.string.should include('3 scenarios: 3 succeeded') + end + + it 'should summarize the number of failed scenarios when the run ends' do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' }) + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' }) + @formatter.run_ended + + # then + @out.string.should include("3 scenarios: 1 succeeded, 2 failed") + end + + it 'should end cleanly (no characters on the last line) with successes' do + # when + @formatter.run_started(1) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario') + @formatter.run_ended + + # then + @out.string.should =~ /\n\z/ + end + + it 'should end cleanly (no characters on the last line) with failures' do + # when + @formatter.run_started(1) + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario', exception_from { raise RuntimeError, 'oops' }) + @formatter.run_ended + + # then + @out.string.should =~ /\n\z/ + end + + it 'should end cleanly (no characters on the last line) with pending steps' do + # when + @formatter.run_started(1) + @formatter.scenario_started(nil, nil) + @formatter.step_pending(:then, 'do pend') + @formatter.scenario_pending('story', 'scenario', exception_from { raise RuntimeError, 'oops' }) + @formatter.run_ended + + # then + @out.string.should =~ /\n\z/ + end + + it 'should summarize the number of pending scenarios when the run ends' do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_pending('story', 'scenario2', 'message') + @formatter.scenario_started(nil, nil) + @formatter.scenario_pending('story', 'scenario3', 'message') + @formatter.run_ended + + # then + @out.string.should include("3 scenarios: 1 succeeded, 0 failed, 2 pending") + end + + it "should only count the first failure in one scenario" do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops' }) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' }) + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' }) + @formatter.run_ended + + # then + @out.string.should include("3 scenarios: 1 succeeded, 2 failed") + end + + it "should only count the first pending in one scenario" do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_pending('story', 'scenario2', 'because ...') + @formatter.scenario_pending('story', 'scenario2', 'because ...') + @formatter.scenario_started(nil, nil) + @formatter.scenario_pending('story', 'scenario3', 'because ...') + @formatter.run_ended + + # then + @out.string.should include("3 scenarios: 1 succeeded, 0 failed, 2 pending") + end + + it "should only count a failure before the first pending in one scenario" do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_pending('story', 'scenario2', exception_from { raise RuntimeError, 'oops' }) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops again' }) + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops' }) + @formatter.run_ended + + # then + @out.string.should include("3 scenarios: 1 succeeded, 1 failed, 1 pending") + end + + it 'should produce details of the first failure each failed scenario when the run ends' do + # when + @formatter.run_started(3) + @formatter.scenario_started(nil, nil) + @formatter.scenario_succeeded('story', 'scenario1') + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2' }) + @formatter.scenario_failed('story', 'scenario2', exception_from { raise RuntimeError, 'oops2 - this one should not appear' }) + @formatter.scenario_started(nil, nil) + @formatter.scenario_failed('story', 'scenario3', exception_from { raise RuntimeError, 'oops3' }) + @formatter.run_ended + + # then + @out.string.should include("FAILURES:\n") + @out.string.should include("1) story (scenario2) FAILED") + @out.string.should include("RuntimeError: oops2") + @out.string.should_not include("RuntimeError: oops2 - this one should not appear") + @out.string.should include("2) story (scenario3) FAILED") + @out.string.should include("RuntimeError: oops3") + end + + it 'should produce details of each pending step when the run ends' do + # when + @formatter.run_started(2) + @formatter.story_started('story 1', 'narrative') + @formatter.scenario_started('story 1', 'scenario 1') + @formatter.step_pending(:given, 'todo 1', []) + @formatter.story_started('story 2', 'narrative') + @formatter.scenario_started('story 2', 'scenario 2') + @formatter.step_pending(:given, 'todo 2', []) + @formatter.run_ended + + # then + @out.string.should include("Pending Steps:\n") + @out.string.should include("1) story 1 (scenario 1): todo 1") + @out.string.should include("2) story 2 (scenario 2): todo 2") + end + + it 'should document a story title and narrative' do + # when + @formatter.story_started 'story', 'narrative' + + # then + @out.string.should include("Story: story\n\n narrative") + end + + it 'should document a scenario name' do + # when + @formatter.scenario_started 'story', 'scenario' + + # then + @out.string.should include("\n\n Scenario: scenario") + end + + it 'should document a step by sentence-casing its name' do + # when + @formatter.step_succeeded :given, 'a context' + @formatter.step_succeeded :when, 'an event' + @formatter.step_succeeded :then, 'an outcome' + + # then + @out.string.should include("\n\n Given a context\n\n When an event\n\n Then an outcome") + end + + it 'should document additional givens using And' do + # when + @formatter.step_succeeded :given, 'step 1' + @formatter.step_succeeded :given, 'step 2' + @formatter.step_succeeded :given, 'step 3' + + # then + @out.string.should include(" Given step 1\n And step 2\n And step 3") + end + + it 'should document additional events using And' do + # when + @formatter.step_succeeded :when, 'step 1' + @formatter.step_succeeded :when, 'step 2' + @formatter.step_succeeded :when, 'step 3' + + # then + @out.string.should include(" When step 1\n And step 2\n And step 3") + end + + it 'should document additional outcomes using And' do + # when + @formatter.step_succeeded :then, 'step 1' + @formatter.step_succeeded :then, 'step 2' + @formatter.step_succeeded :then, 'step 3' + + # then + @out.string.should include(" Then step 1\n And step 2\n And step 3") + end + + it 'should document a GivenScenario followed by a Given using And' do + # when + @formatter.step_succeeded :'given scenario', 'a scenario' + @formatter.step_succeeded :given, 'a context' + + # then + @out.string.should include(" Given scenario a scenario\n And a context") + end + + it 'should document steps with replaced params' do + @formatter.step_succeeded :given, 'a $coloured dog with $n legs', 'pink', 21 + @out.string.should include(" Given a pink dog with 21 legs") + end + + it 'should document regexp steps with replaced params' do + @formatter.step_succeeded :given, /a (pink|blue) dog with (.*) legs/, 'pink', 21 + @out.string.should include(" Given a pink dog with 21 legs") + end + + it "should append PENDING for the first pending step" do + @formatter.scenario_started('','') + @formatter.step_pending(:given, 'a context') + + @out.string.should include('Given a context (PENDING)') + end + + it "should append PENDING for pending after already pending" do + @formatter.scenario_started('','') + @formatter.step_pending(:given, 'a context') + @formatter.step_pending(:when, 'I say hey') + + @out.string.should include('When I say hey (PENDING)') + end + + it "should append FAILED for the first failiure" do + @formatter.scenario_started('','') + @formatter.step_failed(:given, 'a context') + + @out.string.should include('Given a context (FAILED)') + end + + it "should append SKIPPED for the second failiure" do + @formatter.scenario_started('','') + @formatter.step_failed(:given, 'a context') + @formatter.step_failed(:when, 'I say hey') + + @out.string.should include('When I say hey (SKIPPED)') + end + + it "should append SKIPPED for the a failiure after PENDING" do + @formatter.scenario_started('','') + @formatter.step_pending(:given, 'a context') + @formatter.step_failed(:when, 'I say hey') + + @out.string.should include('When I say hey (SKIPPED)') + end + + it 'should print some white space after each story' do + # when + @formatter.story_ended 'title', 'narrative' + + # then + @out.string.should include("\n\n") + end + + it "should print nothing for collected_steps" do + @formatter.collected_steps(['Given a $coloured $animal', 'Given a $n legged eel']) + @out.string.should == ("") + end + + it "should ignore messages it doesn't care about" do + lambda { + @formatter.this_method_does_not_exist + }.should_not raise_error + end + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html b/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html new file mode 100644 index 000000000..3f263747a --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html @@ -0,0 +1,365 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>RSpec results</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta http-equiv="Expires" content="-1" /> + <meta http-equiv="Pragma" content="no-cache" /> + <style type="text/css"> + body { + margin: 0; + padding: 0; + background: #fff; + font-size: 80%; + } + </style> +</head> +<body> +<div class="rspec-report"> + <script type="text/javascript"> + // <![CDATA[ +function moveProgressBar(percentDone) { + document.getElementById("rspec-header").style.width = percentDone +"%"; +} +function makeRed(element_id) { + document.getElementById(element_id).style.background = '#C40D0D'; + document.getElementById(element_id).style.color = '#FFFFFF'; +} + +function makeYellow(element_id) { + if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D') + { + document.getElementById(element_id).style.background = '#FAF834'; + document.getElementById(element_id).style.color = '#000000'; + } + else + { + document.getElementById(element_id).style.background = '#FAF834'; + document.getElementById(element_id).style.color = '#000000'; + } +} + + // ]]> + </script> + <style type="text/css"> +#rspec-header { + background: #65C400; color: #fff; +} + +.rspec-report h1 { + margin: 0px 10px 0px 10px; + padding: 10px; + font-family: "Lucida Grande", Helvetica, sans-serif; + font-size: 1.8em; +} + +#summary { + margin: 0; padding: 5px 10px; + font-family: "Lucida Grande", Helvetica, sans-serif; + text-align: right; + position: absolute; + top: 0px; + right: 0px; +} + +#summary p { + margin: 0 0 0 2px; +} + +#summary #totals { + font-size: 1.2em; +} + +.example_group { + margin: 0 10px 5px; + background: #fff; +} + +dl { + margin: 0; padding: 0 0 5px; + font: normal 11px "Lucida Grande", Helvetica, sans-serif; +} + +dt { + padding: 3px; + background: #65C400; + color: #fff; + font-weight: bold; +} + +dd { + margin: 5px 0 5px 5px; + padding: 3px 3px 3px 18px; +} + +dd.spec.passed { + border-left: 5px solid #65C400; + border-bottom: 1px solid #65C400; + background: #DBFFB4; color: #3D7700; +} + +dd.spec.failed { + border-left: 5px solid #C20000; + border-bottom: 1px solid #C20000; + color: #C20000; background: #FFFBD3; +} + +dd.spec.not_implemented { + border-left: 5px solid #FAF834; + border-bottom: 1px solid #FAF834; + background: #FCFB98; color: #131313; +} + +dd.spec.pending_fixed { + border-left: 5px solid #0000C2; + border-bottom: 1px solid #0000C2; + color: #0000C2; background: #D3FBFF; +} + +.backtrace { + color: #000; + font-size: 12px; +} + +a { + color: #BE5C00; +} + +/* Ruby code, style similar to vibrant ink */ +.ruby { + font-size: 12px; + font-family: monospace; + color: white; + background-color: black; + padding: 0.1em 0 0.2em 0; +} + +.ruby .keyword { color: #FF6600; } +.ruby .constant { color: #339999; } +.ruby .attribute { color: white; } +.ruby .global { color: white; } +.ruby .module { color: white; } +.ruby .class { color: white; } +.ruby .string { color: #66FF00; } +.ruby .ident { color: white; } +.ruby .method { color: #FFCC00; } +.ruby .number { color: white; } +.ruby .char { color: white; } +.ruby .comment { color: #9933CC; } +.ruby .symbol { color: white; } +.ruby .regex { color: #44B4CC; } +.ruby .punct { color: white; } +.ruby .escape { color: white; } +.ruby .interp { color: white; } +.ruby .expr { color: white; } + +.ruby .offending { background-color: gray; } +.ruby .linenum { + width: 75px; + padding: 0.1em 1em 0.2em 0; + color: #000000; + background-color: #FFFBD3; +} + + </style> + +<div id="rspec-header"> + <h1>RSpec Results</h1> + + <div id="summary"> + <p id="totals"> </p> + <p id="duration"> </p> + </div> +</div> + +<div class="results"> +<div class="example_group"> + <dl> + <dt id="example_group_1">Mocker</dt> + <script type="text/javascript">moveProgressBar('5.8');</script> + <dd class="spec passed"><span class="passed_spec_name">should be able to call mock()</span></dd> + <script type="text/javascript">makeRed('rspec-header');</script> + <script type="text/javascript">makeRed('example_group_1');</script> + <script type="text/javascript">moveProgressBar('11.7');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should fail when expected message not received</span> + <div class="failure" id="failure_1"> + <div class="message"><pre>Mock 'poke me' expected :poke with (any args) once, but received it 0 times</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/mocking_example.rb&line=13">./failing_examples/mocking_example.rb:13</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">11</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">should fail when expected message not received</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="linenum">12</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">poke me</span><span class="punct">")</span> +<span class="offending"><span class="linenum">13</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(</span><span class="symbol">:poke</span><span class="punct">)</span></span> +<span class="linenum">14</span> <span class="keyword">end</span> +<span class="linenum">15</span> </code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('17.6');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should fail when messages are received out of order</span> + <div class="failure" id="failure_2"> + <div class="message"><pre>Mock 'one two three' received :three out of order</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/mocking_example.rb&line=22">./failing_examples/mocking_example.rb:22</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">20</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(</span><span class="symbol">:three</span><span class="punct">).</span><span class="ident">ordered</span> +<span class="linenum">21</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">one</span> +<span class="offending"><span class="linenum">22</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">three</span></span> +<span class="linenum">23</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">two</span> +<span class="linenum">24</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('23.5');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should get yelled at when sending unexpected messages</span> + <div class="failure" id="failure_3"> + <div class="message"><pre>Mock 'don't talk to me' expected :any_message_at_all with (any args) 0 times, but received it once</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/mocking_example.rb&line=28">./failing_examples/mocking_example.rb:28</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">26</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">should get yelled at when sending unexpected messages</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="linenum">27</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">don't talk to me</span><span class="punct">")</span> +<span class="offending"><span class="linenum">28</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_not_receive</span><span class="punct">(</span><span class="symbol">:any_message_at_all</span><span class="punct">)</span></span> +<span class="linenum">29</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">any_message_at_all</span> +<span class="linenum">30</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('29.4');</script> + <dd class="spec pending_fixed"> + <span class="failed_spec_name">has a bug we need to fix</span> + <div class="failure" id="failure_4"> + <div class="message"><pre>Expected pending 'here is the bug' to fail. No Error was raised.</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/mocking_example.rb&line=33">./failing_examples/mocking_example.rb:33</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">31</span> +<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">has a bug we need to fix</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="offending"><span class="linenum">33</span> <span class="ident">pending</span> <span class="punct">"</span><span class="string">here is the bug</span><span class="punct">"</span> <span class="keyword">do</span></span> +<span class="linenum">34</span> <span class="comment"># Actually, no. It's fixed. This will fail because it passes :-)</span> +<span class="linenum">35</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">Bug</span><span class="punct">")</span></code></pre> + </div> + </dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_2">Running specs with --diff</dt> + <script type="text/javascript">makeRed('example_group_2');</script> + <script type="text/javascript">moveProgressBar('35.2');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should print diff of different strings</span> + <div class="failure" id="failure_5"> + <div class="message"><pre>expected: "RSpec is a\nbehaviour driven development\nframework for Ruby\n", + got: "RSpec is a\nbehavior driven development\nframework for Ruby\n" (using ==) +Diff: +@@ -1,4 +1,4 @@ + RSpec is a +-behavior driven development ++behaviour driven development + framework for Ruby +</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/diffing_spec.rb&line=13">./failing_examples/diffing_spec.rb:13</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">11</span><span class="ident">framework</span> <span class="keyword">for</span> <span class="constant">Ruby</span> +<span class="linenum">12</span><span class="constant">EOF</span> +<span class="offending"><span class="linenum">13</span> <span class="ident">usa</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="ident">uk</span></span> +<span class="linenum">14</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('41.1');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should print diff of different objects' pretty representation</span> + <div class="failure" id="failure_6"> + <div class="message"><pre>expected <Animal +name=bob, +species=tortoise +> +, got <Animal +name=bob, +species=giraffe +> + (using .eql?) +Diff: +@@ -1,5 +1,5 @@ + <Animal + name=bob, +-species=giraffe ++species=tortoise + > +</pre></div> + <div class="backtrace"><pre><a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/failing_examples/diffing_spec.rb&line=34">./failing_examples/diffing_spec.rb:34</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=52">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:52</a> +<a href="txmt://open?url=file:///Users/aslakhellesoy/scm/rspec/trunk/rspec/spec/spec/runner/formatter/spec_mate_formatter_spec.rb&line=48">./spec/spec/runner/formatter/spec_mate_formatter_spec.rb:48</a> </pre></div> + <pre class="ruby"><code><span class="linenum">32</span> <span class="ident">expected</span> <span class="punct">=</span> <span class="constant">Animal</span><span class="punct">.</span><span class="ident">new</span> <span class="punct">"</span><span class="string">bob</span><span class="punct">",</span> <span class="punct">"</span><span class="string">giraffe</span><span class="punct">"</span> +<span class="linenum">33</span> <span class="ident">actual</span> <span class="punct">=</span> <span class="constant">Animal</span><span class="punct">.</span><span class="ident">new</span> <span class="punct">"</span><span class="string">bob</span><span class="punct">",</span> <span class="punct">"</span><span class="string">tortoise</span><span class="punct">"</span> +<span class="offending"><span class="linenum">34</span> <span class="ident">expected</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eql</span><span class="punct">(</span><span class="ident">actual</span><span class="punct">)</span></span> +<span class="linenum">35</span> <span class="keyword">end</span> +<span class="linenum">36</span><span class="keyword">end</span></code></pre> + </div> + </dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_3">A consumer of a stub</dt> + <script type="text/javascript">moveProgressBar('47.0');</script> + <dd class="spec passed"><span class="passed_spec_name">should be able to stub methods on any Object</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_4">A stubbed method on a class</dt> + <script type="text/javascript">moveProgressBar('52.9');</script> + <dd class="spec passed"><span class="passed_spec_name">should return the stubbed value</span></dd> + <script type="text/javascript">moveProgressBar('58.8');</script> + <dd class="spec passed"><span class="passed_spec_name">should revert to the original method after each spec</span></dd> + <script type="text/javascript">moveProgressBar('64.7');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock the same message</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_5">A mock</dt> + <script type="text/javascript">moveProgressBar('70.5');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub!</span></dd> + <script type="text/javascript">moveProgressBar('76.4');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock</span></dd> + <script type="text/javascript">moveProgressBar('82.3');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock the same message</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_6">pending example (using pending method)</dt> + <script type="text/javascript">makeYellow('example_group_6');</script> + <script type="text/javascript">moveProgressBar('88.2');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should be reported as "PENDING: for some reason" (PENDING: for some reason)</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_7">pending example (with no block)</dt> + <script type="text/javascript">makeYellow('example_group_7');</script> + <script type="text/javascript">moveProgressBar('94.1');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should be reported as "PENDING: Not Yet Implemented" (PENDING: Not Yet Implemented)</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_8">pending example (with block for pending)</dt> + <script type="text/javascript">makeYellow('example_group_8');</script> + <script type="text/javascript">moveProgressBar('100.0');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should have a failing block, passed to pending, reported as "PENDING: for some reason" (PENDING: for some reason)</span></dd> + </dl> +</div> +<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>x seconds</strong>";</script> +<script type="text/javascript">document.getElementById('totals').innerHTML = "17 examples, 6 failures, 3 pending";</script> +</div> +</div> +</body> +</html> diff --git a/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html b/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html new file mode 100644 index 000000000..8a2b12e7d --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html @@ -0,0 +1,365 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>RSpec results</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta http-equiv="Expires" content="-1" /> + <meta http-equiv="Pragma" content="no-cache" /> + <style type="text/css"> + body { + margin: 0; + padding: 0; + background: #fff; + font-size: 80%; + } + </style> +</head> +<body> +<div class="rspec-report"> + <script type="text/javascript"> + // <![CDATA[ +function moveProgressBar(percentDone) { + document.getElementById("rspec-header").style.width = percentDone +"%"; +} +function makeRed(element_id) { + document.getElementById(element_id).style.background = '#C40D0D'; + document.getElementById(element_id).style.color = '#FFFFFF'; +} + +function makeYellow(element_id) { + if (element_id == "rspec-header" && document.getElementById(element_id).style.background != '#C40D0D') + { + document.getElementById(element_id).style.background = '#FAF834'; + document.getElementById(element_id).style.color = '#000000'; + } + else + { + document.getElementById(element_id).style.background = '#FAF834'; + document.getElementById(element_id).style.color = '#000000'; + } +} + + // ]]> + </script> + <style type="text/css"> +#rspec-header { + background: #65C400; color: #fff; +} + +.rspec-report h1 { + margin: 0px 10px 0px 10px; + padding: 10px; + font-family: "Lucida Grande", Helvetica, sans-serif; + font-size: 1.8em; +} + +#summary { + margin: 0; padding: 5px 10px; + font-family: "Lucida Grande", Helvetica, sans-serif; + text-align: right; + position: absolute; + top: 0px; + right: 0px; +} + +#summary p { + margin: 0 0 0 2px; +} + +#summary #totals { + font-size: 1.2em; +} + +.example_group { + margin: 0 10px 5px; + background: #fff; +} + +dl { + margin: 0; padding: 0 0 5px; + font: normal 11px "Lucida Grande", Helvetica, sans-serif; +} + +dt { + padding: 3px; + background: #65C400; + color: #fff; + font-weight: bold; +} + +dd { + margin: 5px 0 5px 5px; + padding: 3px 3px 3px 18px; +} + +dd.spec.passed { + border-left: 5px solid #65C400; + border-bottom: 1px solid #65C400; + background: #DBFFB4; color: #3D7700; +} + +dd.spec.failed { + border-left: 5px solid #C20000; + border-bottom: 1px solid #C20000; + color: #C20000; background: #FFFBD3; +} + +dd.spec.not_implemented { + border-left: 5px solid #FAF834; + border-bottom: 1px solid #FAF834; + background: #FCFB98; color: #131313; +} + +dd.spec.pending_fixed { + border-left: 5px solid #0000C2; + border-bottom: 1px solid #0000C2; + color: #0000C2; background: #D3FBFF; +} + +.backtrace { + color: #000; + font-size: 12px; +} + +a { + color: #BE5C00; +} + +/* Ruby code, style similar to vibrant ink */ +.ruby { + font-size: 12px; + font-family: monospace; + color: white; + background-color: black; + padding: 0.1em 0 0.2em 0; +} + +.ruby .keyword { color: #FF6600; } +.ruby .constant { color: #339999; } +.ruby .attribute { color: white; } +.ruby .global { color: white; } +.ruby .module { color: white; } +.ruby .class { color: white; } +.ruby .string { color: #66FF00; } +.ruby .ident { color: white; } +.ruby .method { color: #FFCC00; } +.ruby .number { color: white; } +.ruby .char { color: white; } +.ruby .comment { color: #9933CC; } +.ruby .symbol { color: white; } +.ruby .regex { color: #44B4CC; } +.ruby .punct { color: white; } +.ruby .escape { color: white; } +.ruby .interp { color: white; } +.ruby .expr { color: white; } + +.ruby .offending { background-color: gray; } +.ruby .linenum { + width: 75px; + padding: 0.1em 1em 0.2em 0; + color: #000000; + background-color: #FFFBD3; +} + + </style> + +<div id="rspec-header"> + <h1>RSpec Results</h1> + + <div id="summary"> + <p id="totals"> </p> + <p id="duration"> </p> + </div> +</div> + +<div class="results"> +<div class="example_group"> + <dl> + <dt id="example_group_1">Mocker</dt> + <script type="text/javascript">moveProgressBar('5.8');</script> + <dd class="spec passed"><span class="passed_spec_name">should be able to call mock()</span></dd> + <script type="text/javascript">makeRed('rspec-header');</script> + <script type="text/javascript">makeRed('example_group_1');</script> + <script type="text/javascript">moveProgressBar('11.7');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should fail when expected message not received</span> + <div class="failure" id="failure_1"> + <div class="message"><pre>Mock 'poke me' expected :poke with (any args) once, but received it 0 times</pre></div> + <div class="backtrace"><pre>./failing_examples/mocking_example.rb:13: +./spec/spec/runner/formatter/html_formatter_spec.rb:18: +./spec/spec/runner/formatter/html_formatter_spec.rb:14:in `chdir' +./spec/spec/runner/formatter/html_formatter_spec.rb:14:</pre></div> + <pre class="ruby"><code><span class="linenum">11</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">should fail when expected message not received</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="linenum">12</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">poke me</span><span class="punct">")</span> +<span class="offending"><span class="linenum">13</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(</span><span class="symbol">:poke</span><span class="punct">)</span></span> +<span class="linenum">14</span> <span class="keyword">end</span> +<span class="linenum">15</span> </code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('17.6');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should fail when messages are received out of order</span> + <div class="failure" id="failure_2"> + <div class="message"><pre>Mock 'one two three' received :three out of order</pre></div> + <div class="backtrace"><pre>./failing_examples/mocking_example.rb:22: +./spec/spec/runner/formatter/html_formatter_spec.rb:18: +./spec/spec/runner/formatter/html_formatter_spec.rb:14:in `chdir' +./spec/spec/runner/formatter/html_formatter_spec.rb:14:</pre></div> + <pre class="ruby"><code><span class="linenum">20</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(</span><span class="symbol">:three</span><span class="punct">).</span><span class="ident">ordered</span> +<span class="linenum">21</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">one</span> +<span class="offending"><span class="linenum">22</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">three</span></span> +<span class="linenum">23</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">two</span> +<span class="linenum">24</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('23.5');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should get yelled at when sending unexpected messages</span> + <div class="failure" id="failure_3"> + <div class="message"><pre>Mock 'don't talk to me' expected :any_message_at_all with (any args) 0 times, but received it once</pre></div> + <div class="backtrace"><pre>./failing_examples/mocking_example.rb:28: +./spec/spec/runner/formatter/html_formatter_spec.rb:18: +./spec/spec/runner/formatter/html_formatter_spec.rb:14:in `chdir' +./spec/spec/runner/formatter/html_formatter_spec.rb:14:</pre></div> + <pre class="ruby"><code><span class="linenum">26</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">should get yelled at when sending unexpected messages</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="linenum">27</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">don't talk to me</span><span class="punct">")</span> +<span class="offending"><span class="linenum">28</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">should_not_receive</span><span class="punct">(</span><span class="symbol">:any_message_at_all</span><span class="punct">)</span></span> +<span class="linenum">29</span> <span class="ident">mock</span><span class="punct">.</span><span class="ident">any_message_at_all</span> +<span class="linenum">30</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('29.4');</script> + <dd class="spec pending_fixed"> + <span class="failed_spec_name">has a bug we need to fix</span> + <div class="failure" id="failure_4"> + <div class="message"><pre>Expected pending 'here is the bug' to fail. No Error was raised.</pre></div> + + <pre class="ruby"><code><span class="linenum">31</span> +<span class="linenum">32</span> <span class="ident">it</span> <span class="punct">"</span><span class="string">has a bug we need to fix</span><span class="punct">"</span> <span class="keyword">do</span> +<span class="offending"><span class="linenum">33</span> <span class="ident">pending</span> <span class="punct">"</span><span class="string">here is the bug</span><span class="punct">"</span> <span class="keyword">do</span></span> +<span class="linenum">34</span> <span class="comment"># Actually, no. It's fixed. This will fail because it passes :-)</span> +<span class="linenum">35</span> <span class="ident">mock</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">("</span><span class="string">Bug</span><span class="punct">")</span></code></pre> + </div> + </dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_2">Running specs with --diff</dt> + <script type="text/javascript">makeRed('example_group_2');</script> + <script type="text/javascript">moveProgressBar('35.2');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should print diff of different strings</span> + <div class="failure" id="failure_5"> + <div class="message"><pre>expected: "RSpec is a\nbehaviour driven development\nframework for Ruby\n", + got: "RSpec is a\nbehavior driven development\nframework for Ruby\n" (using ==) +Diff: +@@ -1,4 +1,4 @@ + RSpec is a +-behavior driven development ++behaviour driven development + framework for Ruby +</pre></div> + + <pre class="ruby"><code><span class="linenum">11</span><span class="ident">framework</span> <span class="keyword">for</span> <span class="constant">Ruby</span> +<span class="linenum">12</span><span class="constant">EOF</span> +<span class="offending"><span class="linenum">13</span> <span class="ident">usa</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="ident">uk</span></span> +<span class="linenum">14</span> <span class="keyword">end</span></code></pre> + </div> + </dd> + <script type="text/javascript">moveProgressBar('41.1');</script> + <dd class="spec failed"> + <span class="failed_spec_name">should print diff of different objects' pretty representation</span> + <div class="failure" id="failure_6"> + <div class="message"><pre>expected <Animal +name=bob, +species=tortoise +> +, got <Animal +name=bob, +species=giraffe +> + (using .eql?) +Diff: +@@ -1,5 +1,5 @@ + <Animal + name=bob, +-species=giraffe ++species=tortoise + > +</pre></div> + <div class="backtrace"><pre>./failing_examples/mocking_example.rb:33: +./spec/spec/runner/formatter/html_formatter_spec.rb:18: +./spec/spec/runner/formatter/html_formatter_spec.rb:14:in `chdir' +./spec/spec/runner/formatter/html_formatter_spec.rb:14:</pre></div> + <pre class="ruby"><code><span class="linenum">32</span> <span class="ident">expected</span> <span class="punct">=</span> <span class="constant">Animal</span><span class="punct">.</span><span class="ident">new</span> <span class="punct">"</span><span class="string">bob</span><span class="punct">",</span> <span class="punct">"</span><span class="string">giraffe</span><span class="punct">"</span> +<span class="linenum">33</span> <span class="ident">actual</span> <span class="punct">=</span> <span class="constant">Animal</span><span class="punct">.</span><span class="ident">new</span> <span class="punct">"</span><span class="string">bob</span><span class="punct">",</span> <span class="punct">"</span><span class="string">tortoise</span><span class="punct">"</span> +<span class="offending"><span class="linenum">34</span> <span class="ident">expected</span><span class="punct">.</span><span class="ident">should</span> <span class="ident">eql</span><span class="punct">(</span><span class="ident">actual</span><span class="punct">)</span></span> +<span class="linenum">35</span> <span class="keyword">end</span> +<span class="linenum">36</span><span class="keyword">end</span></code></pre> + </div> + </dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_3">A consumer of a stub</dt> + <script type="text/javascript">moveProgressBar('47.0');</script> + <dd class="spec passed"><span class="passed_spec_name">should be able to stub methods on any Object</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_4">A stubbed method on a class</dt> + <script type="text/javascript">moveProgressBar('52.9');</script> + <dd class="spec passed"><span class="passed_spec_name">should return the stubbed value</span></dd> + <script type="text/javascript">moveProgressBar('58.8');</script> + <dd class="spec passed"><span class="passed_spec_name">should revert to the original method after each spec</span></dd> + <script type="text/javascript">moveProgressBar('64.7');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock the same message</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_5">A mock</dt> + <script type="text/javascript">moveProgressBar('70.5');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub!</span></dd> + <script type="text/javascript">moveProgressBar('76.4');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock</span></dd> + <script type="text/javascript">moveProgressBar('82.3');</script> + <dd class="spec passed"><span class="passed_spec_name">can stub! and mock the same message</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_6">pending example (using pending method)</dt> + <script type="text/javascript">makeYellow('example_group_6');</script> + <script type="text/javascript">moveProgressBar('88.2');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should be reported as "PENDING: for some reason" (PENDING: for some reason)</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_7">pending example (with no block)</dt> + <script type="text/javascript">makeYellow('example_group_7');</script> + <script type="text/javascript">moveProgressBar('94.1');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should be reported as "PENDING: Not Yet Implemented" (PENDING: Not Yet Implemented)</span></dd> + </dl> +</div> +<div class="example_group"> + <dl> + <dt id="example_group_8">pending example (with block for pending)</dt> + <script type="text/javascript">makeYellow('example_group_8');</script> + <script type="text/javascript">moveProgressBar('100.0');</script> + <dd class="spec not_implemented"><span class="not_implemented_spec_name">should have a failing block, passed to pending, reported as "PENDING: for some reason" (PENDING: for some reason)</span></dd> + </dl> +</div> +<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>x seconds</strong>";</script> +<script type="text/javascript">document.getElementById('totals').innerHTML = "17 examples, 6 failures, 3 pending";</script> +</div> +</div> +</body> +</html> diff --git a/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture.rb b/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture.rb new file mode 100644 index 000000000..444730dc3 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +describe "Running an Example" do + it "should not output twice" do + true.should be_true + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture_runner.rb b/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture_runner.rb new file mode 100644 index 000000000..a0e61316e --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/output_one_time_fixture_runner.rb @@ -0,0 +1,8 @@ +dir = File.dirname(__FILE__) +require "#{dir}/../../spec_helper" + +triggering_double_output = rspec_options +options = Spec::Runner::OptionParser.parse( + ["#{dir}/output_one_time_fixture.rb"], $stderr, $stdout +) +Spec::Runner::CommandLine.run(options) diff --git a/vendor/plugins/rspec/spec/spec/runner/output_one_time_spec.rb b/vendor/plugins/rspec/spec/spec/runner/output_one_time_spec.rb new file mode 100644 index 000000000..8f67a380a --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner/output_one_time_spec.rb @@ -0,0 +1,16 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +module Spec + module Runner + describe CommandLine do + it "should not output twice" do + dir = File.dirname(__FILE__) + Dir.chdir("#{dir}/../../..") do + output =`ruby #{dir}/output_one_time_fixture_runner.rb` + output.should include("1 example, 0 failures") + output.should_not include("0 examples, 0 failures") + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/runner_spec.rb b/vendor/plugins/rspec/spec/spec/runner_spec.rb new file mode 100644 index 000000000..d75e66111 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/runner_spec.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../spec_helper.rb' + +module Spec + describe Runner, ".configure" do + it "should yield global configuration" do + Spec::Runner.configure do |config| + config.should equal(Spec::Runner.configuration) + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/story/builders.rb b/vendor/plugins/rspec/spec/spec/story/builders.rb new file mode 100644 index 000000000..77d50d53e --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/builders.rb @@ -0,0 +1,46 @@ +module Spec + module Story + class StoryBuilder + def initialize + @title = 'a story' + @narrative = 'narrative' + end + + def title(value) + @title = value + self + end + + def narrative(value) + @narrative = value + self + end + + def to_story(&block) + block = lambda {} unless block_given? + Story.new @title, @narrative, &block + end + end + + class ScenarioBuilder + def initialize + @name = 'a scenario' + @story = StoryBuilder.new.to_story + end + + def name(value) + @name = value + self + end + + def story(value) + @story = value + self + end + + def to_scenario(&block) + Scenario.new @story, @name, &block + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/extensions/main_spec.rb b/vendor/plugins/rspec/spec/spec/story/extensions/main_spec.rb new file mode 100644 index 000000000..acdc341ce --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/extensions/main_spec.rb @@ -0,0 +1,161 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' + +module Spec + module Story + module Extensions + describe "the main object extended with Main", :shared => true do + before(:each) do + @main = Class.new do; include Main; end + @original_rspec_story_steps, $rspec_story_steps = $rspec_story_steps, nil + end + + after(:each) do + $rspec_story_steps = @original_rspec_story_steps + end + + def have_step(type, name) + return simple_matcher(%[step group containing a #{type} named #{name.inspect}]) do |actual| + Spec::Story::Step === actual.find(type, name) + end + end + end + + describe Main, "#run_story" do + it_should_behave_like "the main object extended with Main" + + it "should create a PlainTextStoryRunner with run_story" do + Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(mock("runner", :null_object => true)) + @main.run_story + end + + it "should yield the runner if arity == 1" do + File.should_receive(:read).with("some/path").and_return("Story: foo") + $main_spec_runner = nil + @main.run_story("some/path") do |runner| + $main_spec_runner = runner + end + $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner) + end + + it "should run in the runner if arity == 0" do + File.should_receive(:read).with("some/path").and_return("Story: foo") + $main_spec_runner = nil + @main.run_story("some/path") do + $main_spec_runner = self + end + $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner) + end + + it "should tell the PlainTextStoryRunner to run with run_story" do + runner = mock("runner") + Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(runner) + runner.should_receive(:run) + @main.run_story + end + end + + describe Main, "#steps_for" do + it_should_behave_like "the main object extended with Main" + + it "should have no steps for a non existent key" do + @main.steps_for(:key).find(:given, "foo").should be_nil + end + + it "should create steps for a key" do + $main_spec_invoked = false + @main.steps_for(:key) do + Given("foo") { + $main_spec_invoked = true + } + end + @main.steps_for(:key).find(:given, "foo").perform(Object.new, "foo") + $main_spec_invoked.should be_true + end + + it "should append steps to steps_for a given key" do + @main.steps_for(:key) do + Given("first") {} + end + @main.steps_for(:key) do + Given("second") {} + end + @main.steps_for(:key).should have_step(:given, "first") + @main.steps_for(:key).should have_step(:given, "second") + end + end + + describe Main, "#with_steps_for adding new steps" do + it_should_behave_like "the main object extended with Main" + + it "should result in a group containing pre-existing steps and newly defined steps" do + first_group = @main.steps_for(:key) do + Given("first") {} + end + second_group = @main.with_steps_for(:key) do + Given("second") {} + end + + second_group.should have_step(:given, "first") + second_group.should have_step(:given, "second") + end + + it "should not add its steps to the existing group" do + first_group = @main.steps_for(:key) do + Given("first") {} + end + second_group = @main.with_steps_for(:key) do + Given("second") {} + end + + first_group.should have_step(:given, "first") + first_group.should_not have_step(:given, "second") + end + end + + describe Main, "#with_steps_for running a story" do + it_should_behave_like "the main object extended with Main" + + before(:each) do + @runner = mock("runner") + @runner_step_group = StepGroup.new + @runner.stub!(:steps).and_return(@runner_step_group) + @runner.stub!(:run) + Spec::Story::Runner::PlainTextStoryRunner.stub!(:new).and_return(@runner) + end + + it "should create a PlainTextStoryRunner with a path" do + Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with('path/to/file',{}).and_return(@runner) + @main.with_steps_for(:foo) do + run 'path/to/file' + end + end + + it "should create a PlainTextStoryRunner with a path and options" do + Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with(anything,{:bar => :baz}).and_return(@runner) + @main.with_steps_for(:foo) do + run 'path/to/file', :bar => :baz + end + end + + it "should pass the group it creates to the runner's steps" do + steps = @main.steps_for(:ice_cream) do + Given("vanilla") {} + end + @main.with_steps_for(:ice_cream) do + run 'foo' + end + @runner_step_group.should have_step(:given, "vanilla") + end + + it "should run a story" do + @runner.should_receive(:run) + Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(@runner) + @main.with_steps_for(:foo) do + run 'path/to/file' + end + end + + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/story/extensions_spec.rb b/vendor/plugins/rspec/spec/spec/story/extensions_spec.rb new file mode 100644 index 000000000..612ddc72f --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/extensions_spec.rb @@ -0,0 +1,14 @@ +require File.dirname(__FILE__) + '/story_helper' + +require 'spec/story' + +describe Kernel, "#Story" do + before(:each) do + Kernel.stub!(:at_exit) + end + + it "should delegate to ::Spec::Story::Runner.story_runner" do + ::Spec::Story::Runner.story_runner.should_receive(:Story) + story = Story("title","narrative"){} + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/given_scenario_spec.rb b/vendor/plugins/rspec/spec/spec/story/given_scenario_spec.rb new file mode 100644 index 000000000..a688f88d5 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/given_scenario_spec.rb @@ -0,0 +1,27 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe GivenScenario do + it 'should execute a scenario from the current story in its world' do + # given + class MyWorld + attr :scenario_ran + end + instance = World.create(MyWorld) + scenario = ScenarioBuilder.new.to_scenario do + @scenario_ran = true + end + Runner::StoryRunner.should_receive(:scenario_from_current_story).with('scenario name').and_return(scenario) + + step = GivenScenario.new 'scenario name' + + # when + step.perform(instance, nil) + + # then + instance.scenario_ran.should be_true + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/runner/plain_text_story_runner_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/plain_text_story_runner_spec.rb new file mode 100644 index 000000000..1d5f2e0c3 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/plain_text_story_runner_spec.rb @@ -0,0 +1,92 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + describe PlainTextStoryRunner do + before(:each) do + StoryParser.stub!(:new).and_return(@parser = mock("parser")) + @parser.stub!(:parse).and_return([]) + File.stub!(:read).with("path").and_return("this\nand that") + end + + it "should provide access to steps" do + runner = PlainTextStoryRunner.new("path") + + runner.steps do |add| + add.given("baz") {} + end + + runner.steps.find(:given, "baz").should_not be_nil + end + + it "should parse a story file" do + runner = PlainTextStoryRunner.new("path") + + during { + runner.run + }.expect { + @parser.should_receive(:parse).with(["this", "and that"]) + } + end + + it "should build up a mediator with its own steps and the singleton story_runner" do + runner = PlainTextStoryRunner.new("path") + Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner")) + Spec::Story::Runner::StoryMediator.should_receive(:new).with(runner.steps, story_runner, {}). + and_return(mediator = stub("mediator", :run_stories => nil)) + runner.run + end + + it "should build up a parser with the mediator" do + runner = PlainTextStoryRunner.new("path") + Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner")) + Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator = stub("mediator", :run_stories => nil)) + Spec::Story::Runner::StoryParser.should_receive(:new).with(mediator).and_return(@parser) + runner.run + end + + it "should tell the mediator to run the stories" do + runner = PlainTextStoryRunner.new("path") + mediator = mock("mediator") + Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator) + mediator.should_receive(:run_stories) + runner.run + end + + it "should accept a block instead of a path" do + runner = PlainTextStoryRunner.new do |runner| + runner.load("path/to/story") + end + File.should_receive(:read).with("path/to/story").and_return("this\nand that") + runner.run + end + + it "should tell you if you try to run with no path set" do + runner = PlainTextStoryRunner.new + lambda { + runner.run + }.should raise_error(RuntimeError, "You must set a path to the file with the story. See the RDoc.") + end + + it "should pass options to the mediator" do + runner = PlainTextStoryRunner.new("path", :foo => :bar) + Spec::Story::Runner::StoryMediator.should_receive(:new). + with(anything, anything, :foo => :bar). + and_return(mediator = stub("mediator", :run_stories => nil)) + runner.run + end + + it "should provide access to its options" do + runner = PlainTextStoryRunner.new("path") + runner[:foo] = :bar + Spec::Story::Runner::StoryMediator.should_receive(:new). + with(anything, anything, :foo => :bar). + and_return(mediator = stub("mediator", :run_stories => nil)) + runner.run + end + + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/story/runner/scenario_collector_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/scenario_collector_spec.rb new file mode 100644 index 000000000..042c41e8d --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/scenario_collector_spec.rb @@ -0,0 +1,27 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + describe ScenarioCollector do + it 'should construct scenarios with the supplied story' do + # given + story = stub_everything('story') + scenario_collector = ScenarioCollector.new(story) + + # when + scenario_collector.Scenario 'scenario1' do end + scenario_collector.Scenario 'scenario2' do end + scenarios = scenario_collector.scenarios + + # then + scenario_collector.should have(2).scenarios + scenarios.first.name.should == 'scenario1' + scenarios.first.story.should equal(story) + scenarios.last.name.should == 'scenario2' + scenarios.last.story.should equal(story) + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb new file mode 100644 index 000000000..a69ed4a99 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb @@ -0,0 +1,142 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + describe ScenarioRunner do + it 'should run a scenario in its story' do + # given + world = stub_everything + scenario_runner = ScenarioRunner.new + $answer = nil + story = Story.new 'story', 'narrative' do + @answer = 42 # this should be available to the scenario + end + scenario = Scenario.new story, 'scenario' do + $answer = @answer + end + + # when + scenario_runner.run(scenario, world) + + # then + $answer.should == 42 + end + + it 'should allow scenarios to share methods' do + # given + world = stub_everything + $shared_invoked = 0 + story = Story.new 'story', 'narrative' do + def shared + $shared_invoked += 1 + end + end + scenario1 = Scenario.new story, 'scenario1' do + shared() + end + scenario2 = Scenario.new story, 'scenario2' do + shared() + end + scenario_runner = ScenarioRunner.new + + # when + scenario_runner.run(scenario1, world) + scenario_runner.run(scenario2, world) + + # then + $shared_invoked.should == 2 + end + + it 'should notify listeners when a scenario starts' do + # given + world = stub_everything + story = Story.new 'story', 'narrative' do end + scenario = Scenario.new story, 'scenario1' do + # succeeds + end + scenario_runner = ScenarioRunner.new + mock_listener1 = stub_everything('listener1') + mock_listener2 = stub_everything('listener2') + scenario_runner.add_listener(mock_listener1) + scenario_runner.add_listener(mock_listener2) + + # expect + mock_listener1.should_receive(:scenario_started).with('story', 'scenario1') + mock_listener2.should_receive(:scenario_started).with('story', 'scenario1') + + # when + scenario_runner.run(scenario, world) + + # then + end + + it 'should notify listeners when a scenario succeeds' do + # given + world = stub_everything('world') + story = Story.new 'story', 'narrative' do end + scenario = Scenario.new story, 'scenario1' do + # succeeds + end + scenario_runner = ScenarioRunner.new + mock_listener1 = stub_everything('listener1') + mock_listener2 = stub_everything('listener2') + scenario_runner.add_listener(mock_listener1) + scenario_runner.add_listener(mock_listener2) + + # expect + mock_listener1.should_receive(:scenario_succeeded).with('story', 'scenario1') + mock_listener2.should_receive(:scenario_succeeded).with('story', 'scenario1') + + # when + scenario_runner.run(scenario, world) + + # then + end + + it 'should notify listeners ONCE when a scenario raises an error' do + # given + error = RuntimeError.new('oops') + story = Story.new 'title', 'narrative' do end + scenario = Scenario.new story, 'scenario1' do + end + scenario_runner = ScenarioRunner.new + mock_listener = stub_everything('listener') + scenario_runner.add_listener(mock_listener) + world = stub_everything + + # expect + world.should_receive(:errors).twice.and_return([error, error]) + mock_listener.should_receive(:scenario_failed).with('title', 'scenario1', error).once + + # when + scenario_runner.run scenario, world + + # then + end + + it 'should notify listeners when a scenario is pending' do + # given + pending_error = Spec::Example::ExamplePendingError.new('todo') + story = Story.new 'title', 'narrative' do end + scenario = Scenario.new story, 'scenario1' do + end + scenario_runner = ScenarioRunner.new + mock_listener = mock('listener') + scenario_runner.add_listener(mock_listener) + world = stub_everything + + # expect + world.should_receive(:errors).twice.and_return([pending_error, pending_error]) + mock_listener.should_receive(:scenario_started).with('title', 'scenario1') + mock_listener.should_receive(:scenario_pending).with('title', 'scenario1', 'todo').once + + # when + scenario_runner.run scenario, world + + # then + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/runner/story_mediator_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/story_mediator_spec.rb new file mode 100644 index 000000000..4192e483a --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/story_mediator_spec.rb @@ -0,0 +1,133 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + + describe StoryMediator do + before(:each) do + $story_mediator_spec_value = nil + @step_group = StepGroup.new + @step_group.create_matcher(:given, "given") { $story_mediator_spec_value = "given matched" } + @step_group.create_matcher(:when, "when") { $story_mediator_spec_value = "when matched" } + @step_group.create_matcher(:then, "then") { $story_mediator_spec_value = "then matched" } + + @scenario_runner = ScenarioRunner.new + @runner = StoryRunner.new @scenario_runner + @mediator = StoryMediator.new @step_group, @runner + end + + def run_stories + @mediator.run_stories + @runner.run_stories + end + + it "should have no stories" do + @mediator.stories.should be_empty + end + + it "should create two stories" do + @mediator.create_story "story title", "story narrative" + @mediator.create_story "story title 2", "story narrative 2" + run_stories + + @runner.should have(2).stories + @runner.stories.first.title.should == "story title" + @runner.stories.first.narrative.should == "story narrative" + @runner.stories.last.title.should == "story title 2" + @runner.stories.last.narrative.should == "story narrative 2" + end + + it "should create a scenario" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario name" + run_stories + + @runner.should have(1).scenarios + @runner.scenarios.first.name.should == "scenario name" + @runner.scenarios.first.story.should == @runner.stories.first + end + + it "should create a given scenario step if one matches" do + pending("need to untangle the dark mysteries of the story runner - something needs to get stubbed here") do + story = @mediator.create_story "title", "narrative" + @mediator.create_scenario "previous scenario" + @mediator.create_scenario "current scenario" + @mediator.create_given_scenario "previous scenario" + run_stories + + $story_mediator_spec_value.should == "previous scenario matched" + end + end + + it "should create a given step if one matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_given "given" + run_stories + + $story_mediator_spec_value.should == "given matched" + end + + it "should create a pending step if no given step matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_given "no match" + mock_listener = stub_everything("listener") + mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match") + @scenario_runner.add_listener mock_listener + run_stories + end + + it "should create a when step if one matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_when "when" + run_stories + + $story_mediator_spec_value.should == "when matched" + end + + it "should create a pending step if no when step matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_when "no match" + mock_listener = stub_everything("listener") + mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match") + @scenario_runner.add_listener mock_listener + run_stories + end + + it "should create a then step if one matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_then "then" + run_stories + + $story_mediator_spec_value.should == "then matched" + end + + it "should create a pending step if no 'then' step matches" do + @mediator.create_story "title", "narrative" + @mediator.create_scenario "scenario" + @mediator.create_then "no match" + mock_listener = stub_everything("listener") + mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match") + @scenario_runner.add_listener mock_listener + run_stories + end + + it "should pass options to the stories it creates" do + @mediator = StoryMediator.new @step_group, @runner, :foo => :bar + @mediator.create_story "story title", "story narrative" + + run_stories + + @runner.stories.first[:foo].should == :bar + end + + end + + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/story/runner/story_parser_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/story_parser_spec.rb new file mode 100644 index 000000000..5efc8fd18 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/story_parser_spec.rb @@ -0,0 +1,384 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + + describe StoryParser do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + end + + it "should parse no lines" do + @parser.parse([]) + end + + it "should ignore text before the first Story: begins" do + @story_mediator.should_not_receive(:create_scenario) + @story_mediator.should_not_receive(:create_given) + @story_mediator.should_not_receive(:create_when) + @story_mediator.should_not_receive(:create_then) + @story_mediator.should_receive(:create_story).with("simple addition", "") + @parser.parse(["Here is a bunch of text", "about a calculator and all the things", "that it will do", "Story: simple addition"]) + end + + it "should create a story" do + @story_mediator.should_receive(:create_story).with("simple addition", "") + @parser.parse(["Story: simple addition"]) + end + + it "should create a story when line has leading spaces" do + @story_mediator.should_receive(:create_story).with("simple addition", "") + @parser.parse([" Story: simple addition"]) + end + + it "should add a one line narrative to the story" do + @story_mediator.should_receive(:create_story).with("simple addition","narrative") + @parser.parse(["Story: simple addition","narrative"]) + end + + it "should add a multi line narrative to the story" do + @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2\nline 3") + @parser.parse(["Story: simple addition","narrative line 1", "line 2", "line 3"]) + end + + it "should exclude blank lines from the narrative" do + @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2") + @parser.parse(["Story: simple addition","narrative line 1", "", "line 2"]) + end + + it "should exclude Scenario from the narrative" do + @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2") + @story_mediator.should_receive(:create_scenario) + @parser.parse(["Story: simple addition","narrative line 1", "line 2", "Scenario: add one plus one"]) + end + + end + + describe StoryParser, "in Story state" do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + @story_mediator.stub!(:create_story) + end + + it "should create a second Story for Story" do + @story_mediator.should_receive(:create_story).with("number two","") + @parser.parse(["Story: s", "Story: number two"]) + end + + it "should include And in the narrative" do + @story_mediator.should_receive(:create_story).with("s","And foo") + @story_mediator.should_receive(:create_scenario).with("bar") + @parser.parse(["Story: s", "And foo", "Scenario: bar"]) + end + + it "should create a Scenario for Scenario" do + @story_mediator.should_receive(:create_scenario).with("number two") + @parser.parse(["Story: s", "Scenario: number two"]) + end + + it "should include Given in the narrative" do + @story_mediator.should_receive(:create_story).with("s","Given foo") + @story_mediator.should_receive(:create_scenario).with("bar") + @parser.parse(["Story: s", "Given foo", "Scenario: bar"]) + end + + it "should include Given: in the narrative" do + @story_mediator.should_receive(:create_story).with("s","Given: foo") + @story_mediator.should_receive(:create_scenario).with("bar") + @parser.parse(["Story: s", "Given: foo", "Scenario: bar"]) + end + + it "should include When in the narrative" do + @story_mediator.should_receive(:create_story).with("s","When foo") + @story_mediator.should_receive(:create_scenario).with("bar") + @parser.parse(["Story: s", "When foo", "Scenario: bar"]) + end + + it "should include Then in the narrative" do + @story_mediator.should_receive(:create_story).with("s","Then foo") + @story_mediator.should_receive(:create_scenario).with("bar") + @parser.parse(["Story: s", "Then foo", "Scenario: bar"]) + end + + it "should include other in the story" do + @story_mediator.should_receive(:create_story).with("s","narrative") + @parser.parse(["Story: s", "narrative"]) + end + end + + describe StoryParser, "in Scenario state" do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + @story_mediator.stub!(:create_story) + @story_mediator.stub!(:create_scenario) + end + + it "should create a Story for Story" do + @story_mediator.should_receive(:create_story).with("number two","") + @parser.parse(["Story: s", "Scenario: s", "Story: number two"]) + end + + it "should create a Scenario for Scenario" do + @story_mediator.should_receive(:create_scenario).with("number two") + @parser.parse(["Story: s", "Scenario: s", "Scenario: number two"]) + end + + it "should raise for And" do + lambda { + @parser.parse(["Story: s", "Scenario: s", "And second"]) + }.should raise_error(IllegalStepError, /^Illegal attempt to create a And after a Scenario/) + end + + it "should create a Given for Given" do + @story_mediator.should_receive(:create_given).with("gift") + @parser.parse(["Story: s", "Scenario: s", "Given gift"]) + end + + it "should create a Given for Given:" do + @story_mediator.should_receive(:create_given).with("gift") + @parser.parse(["Story: s", "Scenario: s", "Given: gift"]) + end + + it "should create a GivenScenario for GivenScenario" do + @story_mediator.should_receive(:create_given_scenario).with("previous") + @parser.parse(["Story: s", "Scenario: s", "GivenScenario previous"]) + end + + it "should create a GivenScenario for GivenScenario:" do + @story_mediator.should_receive(:create_given_scenario).with("previous") + @parser.parse(["Story: s", "Scenario: s", "GivenScenario: previous"]) + end + + it "should transition to Given state after GivenScenario" do + @story_mediator.stub!(:create_given_scenario) + @parser.parse(["Story: s", "Scenario: s", "GivenScenario previous"]) + @parser.instance_eval{@state}.should be_an_instance_of(StoryParser::GivenState) + end + + it "should transition to Given state after GivenScenario:" do + @story_mediator.stub!(:create_given_scenario) + @parser.parse(["Story: s", "Scenario: s", "GivenScenario: previous"]) + @parser.instance_eval{@state}.should be_an_instance_of(StoryParser::GivenState) + end + + it "should create a When for When" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "When ever"]) + end + + it "should create a When for When:" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "When: ever"]) + end + + it "should create a Then for Then" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Then and there"]) + end + + it "should create a Then for Then:" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Then: and there"]) + end + + it "should ignore other" do + @parser.parse(["Story: s", "Scenario: s", "this is ignored"]) + end + end + + describe StoryParser, "in Given state" do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + @story_mediator.stub!(:create_story) + @story_mediator.stub!(:create_scenario) + @story_mediator.should_receive(:create_given).with("first") + end + + it "should create a Story for Story" do + @story_mediator.should_receive(:create_story).with("number two","") + @parser.parse(["Story: s", "Scenario: s", "Given first", "Story: number two"]) + end + + it "should create a Scenario for Scenario" do + @story_mediator.should_receive(:create_scenario).with("number two") + @parser.parse(["Story: s", "Scenario: s", "Given first", "Scenario: number two"]) + end + + it "should create a second Given for Given" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given first", "Given second"]) + end + + it "should create a second Given for And" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "And second"]) + end + + it "should create a second Given for And:" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given first", "And: second"]) + end + + it "should create a When for When" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When ever"]) + end + + it "should create a When for When:" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When: ever"]) + end + + it "should create a Then for Then" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given first", "Then and there"]) + end + + it "should create a Then for Then:" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given first", "Then: and there"]) + end + + it "should ignore other" do + @parser.parse(["Story: s", "Scenario: s", "Given first", "this is ignored"]) + end + end + + describe StoryParser, "in When state" do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + @story_mediator.stub!(:create_story) + @story_mediator.stub!(:create_scenario) + @story_mediator.should_receive(:create_given).with("first") + @story_mediator.should_receive(:create_when).with("else") + end + + it "should create a Story for Story" do + @story_mediator.should_receive(:create_story).with("number two","") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When: else", "Story: number two"]) + end + + it "should create a Scenario for Scenario" do + @story_mediator.should_receive(:create_scenario).with("number two") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Scenario: number two"]) + end + + it "should create Given for Given" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Given second"]) + end + + it "should create Given for Given:" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Given: second"]) + end + + it "should create a second When for When" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "When ever"]) + end + + it "should create a second When for When:" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "When: ever"]) + end + + it "should create a second When for And" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "And ever"]) + end + + it "should create a second When for And:" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "And: ever"]) + end + + it "should create a Then for Then" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then and there"]) + end + + it "should create a Then for Then:" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: and there"]) + end + + it "should ignore other" do + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "this is ignored"]) + end + end + + describe StoryParser, "in Then state" do + before(:each) do + @story_mediator = mock("story_mediator") + @parser = StoryParser.new(@story_mediator) + @story_mediator.stub!(:create_story) + @story_mediator.stub!(:create_scenario) + @story_mediator.should_receive(:create_given).with("first") + @story_mediator.should_receive(:create_when).with("else") + @story_mediator.should_receive(:create_then).with("what") + end + + it "should create a Story for Story" do + @story_mediator.should_receive(:create_story).with("number two","") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Story: number two"]) + end + + it "should create a Scenario for Scenario" do + @story_mediator.should_receive(:create_scenario).with("number two") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Scenario: number two"]) + end + + it "should create Given for Given" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Given second"]) + end + + it "should create Given for Given:" do + @story_mediator.should_receive(:create_given).with("second") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "Given: second"]) + end + + it "should create When for When" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "When ever"]) + end + + it "should create When for When:" do + @story_mediator.should_receive(:create_when).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "When: ever"]) + end + + it "should create a Then for Then" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Then and there"]) + end + + it "should create a Then for Then:" do + @story_mediator.should_receive(:create_then).with("and there") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "Then: and there"]) + end + + it "should create a second Then for And" do + @story_mediator.should_receive(:create_then).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "And ever"]) + end + + it "should create a second Then for And:" do + @story_mediator.should_receive(:create_then).with("ever") + @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "And: ever"]) + end + + it "should ignore other" do + @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "this is ignored"]) + end + end + end + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec/spec/spec/story/runner/story_runner_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner/story_runner_spec.rb new file mode 100644 index 000000000..0fc46405a --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner/story_runner_spec.rb @@ -0,0 +1,256 @@ +require File.dirname(__FILE__) + '/../story_helper' + +module Spec + module Story + module Runner + describe StoryRunner do + it 'should collect all the stories' do + # given + story_runner = StoryRunner.new(stub('scenario_runner')) + + # when + story_runner.Story 'title1', 'narrative1' do end + story_runner.Story 'title2', 'narrative2' do end + stories = story_runner.stories + + # then + story_runner.should have(2).stories + stories.first.title.should == 'title1' + stories.first.narrative.should == 'narrative1' + stories.last.title.should == 'title2' + stories.last.narrative.should == 'narrative2' + end + + it 'should gather all the scenarios in the stories' do + # given + story_runner = StoryRunner.new(stub('scenario_runner')) + + # when + story_runner.Story "story1", "narrative1" do + Scenario "scenario1" do end + Scenario "scenario2" do end + end + story_runner.Story "story2", "narrative2" do + Scenario "scenario3" do end + end + scenarios = story_runner.scenarios + + # then + story_runner.should have(3).scenarios + scenarios[0].name.should == 'scenario1' + scenarios[1].name.should == 'scenario2' + scenarios[2].name.should == 'scenario3' + end + + # captures worlds passed into a ScenarioRunner + class ScenarioWorldCatcher + attr_accessor :worlds + def run(scenario, world) + (@worlds ||= []) << world + end + end + + it 'should run each scenario in a separate object' do + # given + scenario_world_catcher = ScenarioWorldCatcher.new + story_runner = StoryRunner.new(scenario_world_catcher) + story_runner.Story 'story', 'narrative' do + Scenario 'scenario1' do end + Scenario 'scenario2' do end + end + + # when + story_runner.run_stories + + # then + worlds = scenario_world_catcher.worlds + scenario_world_catcher.should have(2).worlds + worlds[0].should_not == worlds[1] + end + + it 'should use the provided world creator to create worlds' do + # given + stub_scenario_runner = stub_everything + mock_world_creator = mock('world creator') + story_runner = StoryRunner.new(stub_scenario_runner, mock_world_creator) + story_runner.Story 'story', 'narrative' do + Scenario 'scenario1' do end + Scenario 'scenario2' do end + end + + # expect + mock_world_creator.should_receive(:create).twice + + # when + story_runner.run_stories + + # then + end + + it 'should notify listeners of the scenario count when the run starts' do + # given + story_runner = StoryRunner.new(stub_everything) + mock_listener1 = stub_everything('listener1') + mock_listener2 = stub_everything('listener2') + story_runner.add_listener(mock_listener1) + story_runner.add_listener(mock_listener2) + + story_runner.Story 'story1', 'narrative1' do + Scenario 'scenario1' do end + end + story_runner.Story 'story2', 'narrative2' do + Scenario 'scenario2' do end + Scenario 'scenario3' do end + end + + # expect + mock_listener1.should_receive(:run_started).with(3) + mock_listener2.should_receive(:run_started).with(3) + + # when + story_runner.run_stories + + # then + end + + it 'should notify listeners when a story starts' do + # given + story_runner = StoryRunner.new(stub_everything) + mock_listener1 = stub_everything('listener1') + mock_listener2 = stub_everything('listener2') + story_runner.add_listener(mock_listener1) + story_runner.add_listener(mock_listener2) + + story_runner.Story 'story1', 'narrative1' do + Scenario 'scenario1' do end + end + story_runner.Story 'story2', 'narrative2' do + Scenario 'scenario2' do end + Scenario 'scenario3' do end + end + + # expect + mock_listener1.should_receive(:story_started).with('story1', 'narrative1') + mock_listener1.should_receive(:story_ended).with('story1', 'narrative1') + mock_listener2.should_receive(:story_started).with('story2', 'narrative2') + mock_listener2.should_receive(:story_ended).with('story2', 'narrative2') + + # when + story_runner.run_stories + + # then + end + + it 'should notify listeners when the run ends' do + # given + story_runner = StoryRunner.new(stub_everything) + mock_listener1 = stub_everything('listener1') + mock_listener2 = stub_everything('listener2') + story_runner.add_listener mock_listener1 + story_runner.add_listener mock_listener2 + story_runner.Story 'story1', 'narrative1' do + Scenario 'scenario1' do end + end + + # expect + mock_listener1.should_receive(:run_ended) + mock_listener2.should_receive(:run_ended) + + # when + story_runner.run_stories + + # then + end + + it 'should run a story in an instance of a specified class' do + # given + scenario_world_catcher = ScenarioWorldCatcher.new + story_runner = StoryRunner.new(scenario_world_catcher) + story_runner.Story 'title', 'narrative', :type => String do + Scenario 'scenario' do end + end + + # when + story_runner.run_stories + + # then + scenario_world_catcher.worlds[0].should be_kind_of(String) + scenario_world_catcher.worlds[0].should be_kind_of(World) + end + + it 'should pass initialization params through to the constructed instance' do + # given + scenario_world_catcher = ScenarioWorldCatcher.new + story_runner = StoryRunner.new(scenario_world_catcher) + story_runner.Story 'title', 'narrative', :type => Array, :args => [3] do + Scenario 'scenario' do end + end + + # when + story_runner.run_stories + + # then + scenario_world_catcher.worlds[0].should be_kind_of(Array) + scenario_world_catcher.worlds[0].size.should == 3 + end + + it 'should find a scenario in the current story by name' do + # given + story_runner = StoryRunner.new(ScenarioRunner.new) + $scenario = nil + + story_runner.Story 'title', 'narrative' do + Scenario 'first scenario' do + end + Scenario 'second scenario' do + $scenario = StoryRunner.scenario_from_current_story 'first scenario' + end + end + + # when + story_runner.run_stories + + # then + $scenario.name.should == 'first scenario' + end + + it "should clean the steps between stories" do + #given + story_runner = StoryRunner.new(ScenarioRunner.new) + result = mock 'result' + + step1 = Step.new('step') do + result.one + end + steps1 = StepGroup.new + steps1.add :when, step1 + + story_runner.Story 'title', 'narrative', :steps => steps1 do + Scenario 'first scenario' do + When 'step' + end + end + + step2 = Step.new('step') do + result.two + end + steps2 = StepGroup.new + steps2.add :when, step2 + + story_runner.Story 'title2', 'narrative', :steps => steps2 do + Scenario 'second scenario' do + When 'step' + end + end + + #then + result.should_receive(:one) + result.should_receive(:two) + + #when + story_runner.run_stories + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/runner_spec.rb b/vendor/plugins/rspec/spec/spec/story/runner_spec.rb new file mode 100644 index 000000000..81e852640 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/runner_spec.rb @@ -0,0 +1,106 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe Runner, "module" do + def dev_null + io = StringIO.new + def io.write(str) + str.to_s.size + end + return io + end + + before :each do + Kernel.stub!(:at_exit) + @stdout, $stdout = $stdout, dev_null + @argv = Array.new(ARGV) + @runner_module = Runner.dup + @world_creator = World.dup + @runner_module.module_eval { @run_options = @story_runner = @scenario_runner = @world_creator = nil } + end + + after :each do + $stdout = @stdout + ARGV.replace @argv + @runner_module.module_eval { @run_options = @story_runner = @scenario_runner = @world_creator = nil } + end + + it 'should wire up a singleton StoryRunner' do + @runner_module.story_runner.should_not be_nil + end + + it 'should set its options based on ARGV' do + # given + ARGV << '--dry-run' + + # when + options = @runner_module.run_options + + # then + options.dry_run.should be_true + end + + it 'should add a reporter to the runner classes' do + # given + story_runner = mock('story runner', :null_object => true) + scenario_runner = mock('scenario runner', :null_object => true) + world_creator = mock('world', :null_object => true) + + @runner_module::class_eval { @world_creator = world_creator } + @runner_module::StoryRunner.stub!(:new).and_return(story_runner) + @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner) + + # expect + world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter)) + story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter)) + scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter)) + + # when + @runner_module.story_runner + end + + it 'should add a documenter to the runner classes if one is specified' do + # given + ARGV << "--format" << "html" + story_runner = mock('story runner', :null_object => true) + scenario_runner = mock('scenario runner', :null_object => true) + world_creator = mock('world', :null_object => true) + + @runner_module::class_eval { @world_creator = world_creator } + @runner_module::StoryRunner.stub!(:new).and_return(story_runner) + @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner) + + # expect + world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter)) + story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter)) + scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter)) + + # when + @runner_module.story_runner + end + + it 'should add any registered listener to the runner classes' do + # given + ARGV << "--format" << "html" + story_runner = mock('story runner', :null_object => true) + scenario_runner = mock('scenario runner', :null_object => true) + world_creator = mock('world', :null_object => true) + + @runner_module::class_eval { @world_creator = world_creator } + @runner_module::StoryRunner.stub!(:new).and_return(story_runner) + @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner) + + listener = Object.new + + # expect + world_creator.should_receive(:add_listener).with(listener) + story_runner.should_receive(:add_listener).with(listener) + scenario_runner.should_receive(:add_listener).with(listener) + + # when + @runner_module.register_listener listener + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/scenario_spec.rb b/vendor/plugins/rspec/spec/spec/story/scenario_spec.rb new file mode 100644 index 000000000..0cf7aff30 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/scenario_spec.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe Scenario do + it 'should not raise an error if no body is supplied' do + # given + story = StoryBuilder.new.to_story + + # when + error = exception_from do + Scenario.new story, 'name' + end + + # then + error.should be_nil + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/step_group_spec.rb b/vendor/plugins/rspec/spec/spec/story/step_group_spec.rb new file mode 100644 index 000000000..dd28bfa26 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/step_group_spec.rb @@ -0,0 +1,157 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe StepGroup do + before(:each) do + @step_group = StepGroup.new + end + + it "should not find a matcher if empty" do + @step_group.find(:given, "this and that").should be_nil + end + + it "should create a given_scenario matcher" do + step = @step_group.given_scenario("this and that") {} + @step_group.find(:given_scenario, "this and that").should_not be_nil + @step_group.find(:given_scenario, "this and that").should equal(step) + end + + it "should create a given matcher" do + step = @step_group.given("this and that") {} + @step_group.find(:given, "this and that").should equal(step) + end + + it "should create a when matcher" do + step = @step_group.when("this and that") {} + @step_group.find(:when, "this and that").should equal(step) + end + + it "should create a them matcher" do + step = @step_group.then("this and that") {} + @step_group.find(:then, "this and that").should equal(step) + end + + it "should add a matcher object" do + step = Step.new("this and that") {} + @step_group.add(:given, step) + @step_group.find(:given, "this and that").should equal(step) + end + + it "should add it matchers to another StepGroup (with one given)" do + source = StepGroup.new + target = StepGroup.new + step = source.given("this and that") {} + source.add_to target + target.find(:given, "this and that").should equal(step) + end + + it "should add it matchers to another StepGroup (with some of each type)" do + source = StepGroup.new + target = StepGroup.new + given_scenario = source.given_scenario("1") {} + given = source.given("1") {} + when1 = source.when("1") {} + when2 = source.when("2") {} + then1 = source.then("1") {} + then2 = source.then("2") {} + then3 = source.then("3") {} + source.add_to target + target.find(:given_scenario, "1").should equal(given_scenario) + target.find(:given, "1").should equal(given) + target.find(:when, "1").should equal(when1) + target.find(:when, "2").should equal(when2) + target.find(:then, "1").should equal(then1) + target.find(:then, "2").should equal(then2) + target.find(:then, "3").should equal(then3) + end + + it "should append another collection" do + matchers_to_append = StepGroup.new + step = matchers_to_append.given("this and that") {} + @step_group << matchers_to_append + @step_group.find(:given, "this and that").should equal(step) + end + + it "should append several other collections" do + matchers_to_append = StepGroup.new + more_matchers_to_append = StepGroup.new + first_matcher = matchers_to_append.given("this and that") {} + second_matcher = more_matchers_to_append.given("and the other") {} + @step_group << matchers_to_append + @step_group << more_matchers_to_append + @step_group.find(:given, "this and that").should equal(first_matcher) + @step_group.find(:given, "and the other").should equal(second_matcher) + end + + it "should yield itself on initialization" do + begin + $step_group_spec_step = nil + matchers = StepGroup.new do |matchers| + $step_group_spec_step = matchers.given("foo") {} + end + $step_group_spec_step.matches?("foo").should be_true + ensure + $step_group_spec_step = nil + end + end + + it "should support defaults" do + class StepGroupSubclass < StepGroup + steps do |add| + add.given("foo") {} + end + end + StepGroupSubclass.new.find(:given, "foo").should_not be_nil + end + + it "should create a Given" do + sub = Class.new(StepGroup).new + step = sub.Given("foo") {} + sub.find(:given, "foo").should == step + end + + it "should create a When" do + sub = Class.new(StepGroup).new + step = sub.When("foo") {} + sub.find(:when, "foo").should == step + end + + it "should create a Then" do + sub = Class.new(StepGroup).new + step = sub.Then("foo") {} + sub.find(:then, "foo").should == step + end + + it "should create steps in a block" do + sub = Class.new(StepGroup).new do + Given("a given") {} + When("a when") {} + Then("a then") {} + end + sub.find(:given, "a given").should_not be_nil + sub.find(:when, "a when").should_not be_nil + sub.find(:then, "a then").should_not be_nil + end + + it "should clear itself" do + step = @step_group.given("this and that") {} + @step_group.clear + @step_group.find(:given, "this and that").should be_nil + end + + it "should tell you when it is empty" do + @step_group.should be_empty + end + + it "should tell you when it is not empty" do + @step_group.given("this and that") {} + @step_group.should_not be_empty + end + + it "should handle << nil" do + @step_group << nil + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/step_mother_spec.rb b/vendor/plugins/rspec/spec/spec/story/step_mother_spec.rb new file mode 100644 index 000000000..64efd7a6a --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/step_mother_spec.rb @@ -0,0 +1,72 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe StepMother do + it 'should store a step by name and type' do + # given + step_mother = StepMother.new + step = Step.new("a given", &lambda {}) + step_mother.store(:given, step) + + # when + found = step_mother.find(:given, "a given") + + # then + found.should == step + end + + it 'should NOT raise an error if a step is missing' do + # given + step_mother = StepMother.new + + # then + lambda do + # when + step_mother.find(:given, "doesn't exist") + end.should_not raise_error + end + + it "should create a default step which raises a pending error" do + # given + step_mother = StepMother.new + + # when + step = step_mother.find(:given, "doesn't exist") + + # then + step.should be_an_instance_of(Step) + + lambda do + step.perform(Object.new, "doesn't exist") + end.should raise_error(Spec::Example::ExamplePendingError, /Unimplemented/) + end + + it 'should clear itself' do + # given + step_mother = StepMother.new + step = Step.new("a given") do end + step_mother.store(:given, step) + + # when + step_mother.clear + + # then + step_mother.should be_empty + end + + it "should use assigned steps" do + step_mother = StepMother.new + + step = Step.new('step') {} + step_group = StepGroup.new + step_group.add(:given, step) + + step_mother.use(step_group) + + step_mother.find(:given, "step").should equal(step) + end + + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/step_spec.rb b/vendor/plugins/rspec/spec/spec/story/step_spec.rb new file mode 100644 index 000000000..ec6628809 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/step_spec.rb @@ -0,0 +1,178 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe Step, "matching" do + it "should match a text string" do + step = Step.new("this text") {} + step.matches?("this text").should be_true + end + + it "should not match a text string that does not start the same" do + step = Step.new("this text") {} + step.matches?("Xthis text").should be_false + end + + it "should not match a text string that does not end the same" do + step = Step.new("this text") {} + step.matches?("this textX").should be_false + end + + it "should match a text string with a param" do + step = Step.new("this $param text") {} + step.matches?("this anything text").should be_true + end + + it "should not be greedy" do + step = Step.new("enter $value for $key") {} + step.parse_args("enter 3 for keys for a piano").should == ['3','keys for a piano'] + end + + it "should match a text string with 3 params" do + step = Step.new("1 $one 2 $two 3 $three 4") {} + step.matches?("1 a 2 b 3 c 4").should be_true + end + + it "should match a text string with a param at the beginning" do + step = Step.new("$one 2 3") {} + step.matches?("a 2 3").should be_true + end + + it "should match a text string with a param at the end" do + step = Step.new("1 2 $three") {} + step.matches?("1 2 c").should be_true + end + + it "should not match a different string" do + step = Step.new("this text") {} + step.matches?("other text").should be_false + end + + it "should match a regexp" do + step = Step.new(/this text/) {} + step.matches?("this text").should be_true + end + + it "should match a regexp with a match group" do + step = Step.new(/this (.*) text/) {} + step.matches?("this anything text").should be_true + end + + it "should not match a non matching regexp" do + step = Step.new(/this (.*) text/) {} + step.matches?("other anything text").should be_false + end + + it "should not get bogged down by parens in strings" do + step = Step.new("before () after") {} + step.matches?("before () after").should be_true + end + + it "should match any option of an alteration" do + step = Step.new(/(he|she) is cool/) {} + step.matches?("he is cool").should be_true + step.matches?("she is cool").should be_true + end + + it "should match alteration as well as a variable" do + step = Step.new(/(he|she) is (.*)/) {} + step.matches?("he is cool").should be_true + step.parse_args("he is cool").should == ['he', 'cool'] + end + + end + + describe Step do + it "should make complain with no block" do + lambda { + step = Step.new("foo") + }.should raise_error + end + + it "should perform itself on an object" do + # given + $instance = nil + step = Step.new 'step' do + $instance = self + end + instance = Object.new + + # when + step.perform(instance, "step") + + # then + $instance.should == instance + end + + it "should perform itself with one parameter with match expression" do + # given + $result = nil + step = Step.new 'an account with $count dollars' do |count| + $result = count + end + instance = Object.new + + # when + args = step.parse_args("an account with 3 dollars") + step.perform(instance, *args) + + # then + $result.should == "3" + end + + it "should perform itself with one parameter without a match expression" do + # given + $result = nil + step = Step.new 'an account with a balance of' do |amount| + $result = amount + end + instance = Object.new + + # when + step.perform(instance, 20) + + # then + $result.should == 20 + end + + it "should perform itself with 2 parameters" do + # given + $account_type = nil + $amount = nil + step = Step.new 'a $account_type account with $amount dollars' do |account_type, amount| + $account_type = account_type + $amount = amount + end + instance = Object.new + + # when + args = step.parse_args("a savings account with 3 dollars") + step.perform(instance, *args) + + # then + $account_type.should == "savings" + $amount.should == "3" + end + + it "should perform itself when defined with a regexp with 2 parameters" do + # given + $pronoun = nil + $adjective = nil + step = Step.new /(he|she) is (.*)/ do |pronoun, adjective| + $pronoun = pronoun + $adjective = adjective + end + instance = Object.new + + # when + args = step.parse_args("he is cool") + step.perform(instance, *args) + + # then + $pronoun.should == "he" + $adjective.should == "cool" + end + + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/story_helper.rb b/vendor/plugins/rspec/spec/spec/story/story_helper.rb new file mode 100644 index 000000000..bb906f255 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/story_helper.rb @@ -0,0 +1,2 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/builders' diff --git a/vendor/plugins/rspec/spec/spec/story/story_spec.rb b/vendor/plugins/rspec/spec/spec/story/story_spec.rb new file mode 100644 index 000000000..21257e9a7 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/story_spec.rb @@ -0,0 +1,86 @@ +require File.dirname(__FILE__) + '/story_helper' + +module Spec + module Story + describe Story do + it 'should run itself in a given object' do + # given + $instance = nil + story = Story.new 'title', 'narrative' do + $instance = self + end + object = Object.new + + # when + story.run_in(object) + + # then + $instance.should be(object) + end + + it 'should not raise an error if no block is supplied' do + # when + error = exception_from do + Story.new 'title', 'narrative' + end + + # then + error.should be_nil + end + + it "should raise when error raised running in another object" do + #given + story = Story.new 'title', 'narrative' do + raise "this is raised in the story" + end + object = Object.new + + # when/then + lambda do + story.run_in(object) + end.should raise_error + end + + it "should use the steps it is told to using a StepGroup" do + story = Story.new("title", "narrative", :steps => steps = StepGroup.new) do end + assignee = mock("assignee") + assignee.should_receive(:use).with(steps) + story.assign_steps_to(assignee) + end + + it "should use the steps it is told to using a key" do + begin + orig_rspec_story_steps = $rspec_story_steps + $rspec_story_steps = StepGroupHash.new + $rspec_story_steps[:foo] = steps = Object.new + + story = Story.new("title", "narrative", :steps_for => :foo) do end + assignee = mock("assignee") + + assignee.should_receive(:use).with(steps) + story.assign_steps_to(assignee) + ensure + $rspec_story_steps = orig_rspec_story_steps + end + end + + it "should use the steps it is told to using multiple keys" do + begin + orig_rspec_story_steps = $rspec_story_steps + $rspec_story_steps = StepGroupHash.new + $rspec_story_steps[:foo] = foo_steps = Object.new + $rspec_story_steps[:bar] = bar_steps = Object.new + + story = Story.new("title", "narrative", :steps_for => [:foo, :bar]) do end + assignee = mock("assignee") + + assignee.should_receive(:use).with(foo_steps) + assignee.should_receive(:use).with(bar_steps) + story.assign_steps_to(assignee) + ensure + $rspec_story_steps = orig_rspec_story_steps + end + end + end + end +end diff --git a/vendor/plugins/rspec/spec/spec/story/world_spec.rb b/vendor/plugins/rspec/spec/spec/story/world_spec.rb new file mode 100644 index 000000000..85410f612 --- /dev/null +++ b/vendor/plugins/rspec/spec/spec/story/world_spec.rb @@ -0,0 +1,416 @@ +require File.dirname(__FILE__) + '/story_helper' + +require 'spec/story' + +module Spec + module Story + describe World do + before :each do + World.listeners.clear + end + + after :each do + World.listeners.clear + World.step_mother.clear + end + + it 'should create an object that mixes in a World' do + # when + obj = World::create + + # then + obj.should be_kind_of(World) + end + + it 'should create a World from any object type' do + # when + obj = World::create String + + # then + obj.should be_kind_of(String) + obj.should be_kind_of(World) + end + + it 'should pass arguments to #new when creating an object of a specified type that mixes in a world' do + # given + Thing = Struct.new(:name, :age) + + # when + obj = World::create Thing, "David", "I'm not telling" + + # then + obj.should be_an_instance_of(Thing) + obj.name.should == "David" + obj.age.should == "I'm not telling" + obj.should be_kind_of(World) + end + + def ensure_world_executes_step(&block) + # given + obj = World::create + $step_ran = false + + # when + obj.instance_eval(&block) + + # then + $step_ran.should be_true + end + + it 'should execute a Given, When or Then step' do + ensure_world_executes_step do + Given 'a given' do + $step_ran = true + end + end + + ensure_world_executes_step do + When 'an event' do + $step_ran = true + end + end + + ensure_world_executes_step do + Then 'an outcome' do + $step_ran = true + end + end + end + + it 'should interpret Given... And... as multiple givens' do + # given + world = World.create + $steps = [] + + # when + world.instance_eval do + Given 'step 1' do + $steps << 1 + end + And 'step 2' do + $steps << 2 + end + end + + # then + $steps.should == [1,2] + World.step_mother.find(:given, 'step 1').should_not be_nil + World.step_mother.find(:given, 'step 2').should_not be_nil + end + + it 'should interpret When... And... as multiple events' do + # given + world = World.create + $steps = [] + + # when + world.instance_eval do + When 'step 1' do + $steps << 1 + end + And 'step 2' do + $steps << 2 + end + end + + # then + $steps.should == [1,2] + World.step_mother.find(:when, 'step 1').should_not be_nil + World.step_mother.find(:when, 'step 2').should_not be_nil + end + + it 'should interpret Then... And... as multiple outcomes' do + # given + world = World.create + $steps = [] + + # when + world.instance_eval do + Then 'step 1' do + $steps << 1 + end + And 'step 2' do + $steps << 2 + end + end + + # then + $steps.should == [1,2] + World.step_mother.find(:then, 'step 1').should_not be_nil + World.step_mother.find(:then, 'step 2').should_not be_nil + end + + it 'should reuse a given across scenarios' do + # given + $num_invoked = 0 + a_world = World::create + a_world.instance_eval do + Given 'a given' do + $num_invoked += 1 + end + end + another_world = World::create + + # when + another_world.instance_eval do + Given 'a given' # without a body + end + + # then + $num_invoked.should == 2 + end + + it 'should reuse an event across scenarios' do + # given + $num_invoked = 0 + a_world = World::create + a_world.instance_eval do + When 'an event' do + $num_invoked += 1 + end + end + + another_world = World::create + + # when + another_world.instance_eval do + When 'an event' # without a body + end + + # then + $num_invoked.should == 2 + end + + it 'should reuse an outcome across scenarios' do + # given + $num_invoked = 0 + a_world = World::create + a_world.instance_eval do + Then 'an outcome' do + $num_invoked += 1 + end + end + + another_world = World::create + + # when + another_world.instance_eval do + Then 'an outcome' # without a body + end + + # then + $num_invoked.should == 2 + end + + it 'should preserve instance variables between steps within a scenario' do + # given + world = World::create + $first = nil + $second = nil + + # when + world.instance_eval do + Given 'given' do + @first = 'first' + end + When 'event' do + @second = @first # from given + end + Then 'outcome' do + $first = @first # from given + $second = @second # from event + end + end + + # then + $first.should == 'first' + $second.should == 'first' + end + + it 'should invoke a reused step in the new object instance' do + # given + $instances = [] + $debug = true + world1 = World.create + world1.instance_eval do + Given 'a given' do + $instances << self.__id__ + end + end + world2 = World.create + + # when + world2.instance_eval do + Given 'a given' # reused + Then 'an outcome' do + $instances << __id__ + end + end + $debug = false + # then + $instances.should == [ world1.__id__, world2.__id__, world2.__id__ ] + end + + def ensure_world_collects_error(expected_error, &block) + # given + world = World.create + # $error = nil + + # when + world.start_collecting_errors + world.instance_eval(&block) + + # then + world.should have(1).errors + world.errors[0].should be_kind_of(expected_error) + end + + it 'should collect a failure from a Given step' do + ensure_world_collects_error RuntimeError do + Given 'a given' do + raise RuntimeError, "oops" + end + end + end + + it 'should collect a failure from a When step' do + ensure_world_collects_error RuntimeError do + When 'an event' do + raise RuntimeError, "oops" + end + end + end + + it 'should collect a failure from a Then step' do + ensure_world_collects_error RuntimeError do + Then 'an outcome' do + raise RuntimeError, "oops" + end + end + end + + it 'should inform listeners when it runs a Given, When or Then step' do + # given + world = World.create + mock_listener1 = mock('listener1') + mock_listener2 = mock('listener2') + World.add_listener(mock_listener1) + World.add_listener(mock_listener2) + + # expect + mock_listener1.should_receive(:step_succeeded).with(:given, 'a context') + mock_listener1.should_receive(:step_succeeded).with(:when, 'an event') + mock_listener1.should_receive(:step_succeeded).with(:then, 'an outcome') + + mock_listener2.should_receive(:step_succeeded).with(:given, 'a context') + mock_listener2.should_receive(:step_succeeded).with(:when, 'an event') + mock_listener2.should_receive(:step_succeeded).with(:then, 'an outcome') + + # when + world.instance_eval do + Given 'a context' do end + When 'an event' do end + Then 'an outcome' do end + end + + # then + end + + it 'should tell listeners but not execute the step in dry-run mode' do + # given + Runner.stub!(:dry_run).and_return(true) + mock_listener = mock('listener') + World.add_listener(mock_listener) + $step_invoked = false + world = World.create + + # expect + mock_listener.should_receive(:step_succeeded).with(:given, 'a context') + + # when + world.instance_eval do + Given 'a context' do + $step_invoked = true + end + end + + # then + $step_invoked.should be(false) + end + + it 'should suppress listeners while it runs a GivenScenario' do + # given + $scenario_ran = false + + scenario = ScenarioBuilder.new.name('a scenario').to_scenario do + $scenario_ran = true + Given 'given' do end + When 'event' do end + Then 'outcome' do end + end + + given_scenario = GivenScenario.new('a scenario') + Runner::StoryRunner.should_receive(:scenario_from_current_story). + with('a scenario').and_return(scenario) + + world = World.create + listener = mock('listener') + World.add_listener(listener) + + # expect + listener.should_receive(:found_scenario).with(:'given scenario', 'a scenario') + listener.should_receive(:step_succeeded).never.with(:given, 'given') + listener.should_receive(:step_succeeded).never.with(:when, 'event') + listener.should_receive(:step_succeeded).never.with(:then, 'outcome') + + # when + world.GivenScenario 'a scenario' + + # then + $scenario_ran.should be_true + end + + it 'should interpret GivenScenario... And... as multiple givens' do + # given + world = World.create + $steps = [] + + scenario = ScenarioBuilder.new.name('a scenario').to_scenario do + $steps << 1 + end + Runner::StoryRunner.should_receive(:scenario_from_current_story). + with('a scenario').and_return(scenario) + + # when + world.instance_eval do + GivenScenario 'a scenario' + And 'step 2' do + $steps << 2 + end + end + + # then + $steps.should == [1,2] + World.step_mother.find(:given, 'step 2').should_not be_nil + end + + it 'should provide rspec matchers' do + # given + world = World.create + + # then + world.instance_eval do + 'hello'.should match(/^hello$/) + end + end + + it "should use assigned matchers" do + world = World.create + + World.should_receive(:use).with(steps = Object.new) + + World.use(steps) + end + end + end +end |