diff options
author | louise <louise> | 2007-10-16 19:10:21 +0000 |
---|---|---|
committer | louise <louise> | 2007-10-16 19:10:21 +0000 |
commit | d350850897a5ee7a994d3c618529cf5beecf71ea (patch) | |
tree | 39de7013d0a3377f063fbd53da7c89f207eeedd0 /vendor/plugins/rspec/failing_examples | |
parent | 3b1d8bfdeea68da1ad083a305d0df8f458c362a0 (diff) |
Adding rspec plugin
Diffstat (limited to 'vendor/plugins/rspec/failing_examples')
14 files changed, 329 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/failing_examples/diffing_spec.rb b/vendor/plugins/rspec/failing_examples/diffing_spec.rb new file mode 100644 index 000000000..85e13e8c0 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/diffing_spec.rb @@ -0,0 +1,36 @@ +describe "Running specs with --diff" do + it "should print diff of different strings" do + uk = <<-EOF +RSpec is a +behaviour driven development +framework for Ruby +EOF + usa = <<-EOF +RSpec is a +behavior driven development +framework for Ruby +EOF + usa.should == uk + end + + class Animal + def initialize(name,species) + @name,@species = name,species + end + + def inspect + <<-EOA +<Animal +name=#{@name}, +species=#{@species} +> + EOA + end + end + + it "should print diff of different objects' pretty representation" do + expected = Animal.new "bob", "giraffe" + actual = Animal.new "bob", "tortoise" + expected.should eql(actual) + end +end diff --git a/vendor/plugins/rspec/failing_examples/failure_in_setup.rb b/vendor/plugins/rspec/failing_examples/failure_in_setup.rb new file mode 100644 index 000000000..2a807a99a --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/failure_in_setup.rb @@ -0,0 +1,10 @@ +describe "This example" do + + before(:each) do + NonExistentClass.new + end + + it "should be listed as failing in setup" do + end + +end diff --git a/vendor/plugins/rspec/failing_examples/failure_in_teardown.rb b/vendor/plugins/rspec/failing_examples/failure_in_teardown.rb new file mode 100644 index 000000000..6458ea2b8 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/failure_in_teardown.rb @@ -0,0 +1,10 @@ +describe "This example" do + + it "should be listed as failing in teardown" do + end + + after(:each) do + NonExistentClass.new + end + +end diff --git a/vendor/plugins/rspec/failing_examples/mocking_example.rb b/vendor/plugins/rspec/failing_examples/mocking_example.rb new file mode 100644 index 000000000..caf2db036 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/mocking_example.rb @@ -0,0 +1,40 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe "Mocker" do + + it "should be able to call mock()" do + mock = mock("poke me") + mock.should_receive(:poke) + mock.poke + end + + it "should fail when expected message not received" do + mock = mock("poke me") + mock.should_receive(:poke) + end + + it "should fail when messages are received out of order" do + mock = mock("one two three") + mock.should_receive(:one).ordered + mock.should_receive(:two).ordered + mock.should_receive(:three).ordered + mock.one + mock.three + mock.two + end + + it "should get yelled at when sending unexpected messages" do + mock = mock("don't talk to me") + mock.should_not_receive(:any_message_at_all) + mock.any_message_at_all + end + + it "has a bug we need to fix" do + pending "here is the bug" do + # Actually, no. It's fixed. This will fail because it passes :-) + mock = mock("Bug") + mock.should_receive(:hello) + mock.hello + end + end +end diff --git a/vendor/plugins/rspec/failing_examples/mocking_with_flexmock.rb b/vendor/plugins/rspec/failing_examples/mocking_with_flexmock.rb new file mode 100644 index 000000000..6e79ece0e --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/mocking_with_flexmock.rb @@ -0,0 +1,26 @@ +# stub frameworks like to gum up Object, so this is deliberately +# set NOT to run so that you don't accidentally run it when you +# run this dir. + +# To run it, stand in this directory and say: +# +# RUN_FLEXMOCK_EXAMPLE=true ruby ../bin/spec mocking_with_flexmock.rb + +if ENV['RUN_FLEXMOCK_EXAMPLE'] + Spec::Runner.configure do |config| + config.mock_with :flexmock + end + + describe "Flexmocks" do + it "should fail when the expected message is received with wrong arguments" do + m = flexmock("now flex!") + m.should_receive(:msg).with("arg").once + m.msg("other arg") + end + + it "should fail when the expected message is not received at all" do + m = flexmock("now flex!") + m.should_receive(:msg).with("arg").once + end + end +end diff --git a/vendor/plugins/rspec/failing_examples/mocking_with_mocha.rb b/vendor/plugins/rspec/failing_examples/mocking_with_mocha.rb new file mode 100644 index 000000000..f14a1a3e5 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/mocking_with_mocha.rb @@ -0,0 +1,25 @@ +# stub frameworks like to gum up Object, so this is deliberately +# set NOT to run so that you don't accidentally run it when you +# run this dir. + +# To run it, stand in this directory and say: +# +# RUN_MOCHA_EXAMPLE=true ruby ../bin/spec mocking_with_mocha.rb + +if ENV['RUN_MOCHA_EXAMPLE'] + Spec::Runner.configure do |config| + config.mock_with :mocha + end + describe "Mocha framework" do + it "should should be made available by saying config.mock_with :mocha" do + m = mock() + m.expects(:msg).with("arg") + m.msg + end + it "should should be made available by saying config.mock_with :mocha" do + o = Object.new + o.expects(:msg).with("arg") + o.msg + end + end +end diff --git a/vendor/plugins/rspec/failing_examples/mocking_with_rr.rb b/vendor/plugins/rspec/failing_examples/mocking_with_rr.rb new file mode 100644 index 000000000..0d2b4fe04 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/mocking_with_rr.rb @@ -0,0 +1,27 @@ +# stub frameworks like to gum up Object, so this is deliberately +# set NOT to run so that you don't accidentally run it when you +# run this dir. + +# To run it, stand in this directory and say: +# +# RUN_RR_EXAMPLE=true ruby ../bin/spec mocking_with_rr.rb + +if ENV['RUN_RR_EXAMPLE'] + Spec::Runner.configure do |config| + config.mock_with :rr + end + describe "RR framework" do + it "should should be made available by saying config.mock_with :rr" do + o = Object.new + mock(o).msg("arg") + o.msg + end + it "should should be made available by saying config.mock_with :rr" do + o = Object.new + mock(o) do |m| + m.msg("arg") + end + o.msg + end + end +end diff --git a/vendor/plugins/rspec/failing_examples/partial_mock_example.rb b/vendor/plugins/rspec/failing_examples/partial_mock_example.rb new file mode 100644 index 000000000..6d0554055 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/partial_mock_example.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/spec_helper' + +class MockableClass + def self.find id + return :original_return + end +end + +describe "A partial mock" do + + it "should work at the class level (but fail here due to the type mismatch)" do + MockableClass.should_receive(:find).with(1).and_return {:stub_return} + MockableClass.find("1").should equal(:stub_return) + end + + it "should revert to the original after each spec" do + MockableClass.find(1).should equal(:original_return) + end + +end diff --git a/vendor/plugins/rspec/failing_examples/predicate_example.rb b/vendor/plugins/rspec/failing_examples/predicate_example.rb new file mode 100644 index 000000000..df54d7337 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/predicate_example.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/spec_helper' + +class BddFramework + def intuitive? + true + end + + def adopted_quickly? + #this will cause failures because it reallly SHOULD be adopted quickly + false + end +end + +describe "BDD framework" do + + before(:each) do + @bdd_framework = BddFramework.new + end + + it "should be adopted quickly" do + #this will fail because it reallly SHOULD be adopted quickly + @bdd_framework.should be_adopted_quickly + end + + it "should be intuitive" do + @bdd_framework.should be_intuitive + end + +end diff --git a/vendor/plugins/rspec/failing_examples/raising_example.rb b/vendor/plugins/rspec/failing_examples/raising_example.rb new file mode 100644 index 000000000..e40b51ec8 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/raising_example.rb @@ -0,0 +1,47 @@ +describe "This example" do + + it "should show that a NoMethodError is raised but an Exception was expected" do + proc { ''.nonexistent_method }.should raise_error + end + + it "should pass" do + proc { ''.nonexistent_method }.should raise_error(NoMethodError) + end + + it "should show that a NoMethodError is raised but a SyntaxError was expected" do + proc { ''.nonexistent_method }.should raise_error(SyntaxError) + end + + it "should show that nothing is raised when SyntaxError was expected" do + proc { }.should raise_error(SyntaxError) + end + + it "should show that a NoMethodError is raised but a Exception was expected" do + proc { ''.nonexistent_method }.should_not raise_error + end + + it "should show that a NoMethodError is raised" do + proc { ''.nonexistent_method }.should_not raise_error(NoMethodError) + end + + it "should also pass" do + proc { ''.nonexistent_method }.should_not raise_error(SyntaxError) + end + + it "should show that a NoMethodError is raised when nothing expected" do + proc { ''.nonexistent_method }.should_not raise_error(Exception) + end + + it "should show that the wrong message was received" do + proc { raise StandardError.new("what is an enterprise?") }.should raise_error(StandardError, "not this") + end + + it "should show that the unexpected error/message was thrown" do + proc { raise StandardError.new("abc") }.should_not raise_error(StandardError, "abc") + end + + it "should pass too" do + proc { raise StandardError.new("abc") }.should_not raise_error(StandardError, "xyz") + end + +end diff --git a/vendor/plugins/rspec/failing_examples/spec_helper.rb b/vendor/plugins/rspec/failing_examples/spec_helper.rb new file mode 100644 index 000000000..61f51fbdb --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/spec_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../lib/spec' diff --git a/vendor/plugins/rspec/failing_examples/syntax_error_example.rb b/vendor/plugins/rspec/failing_examples/syntax_error_example.rb new file mode 100644 index 000000000..c9bb90774 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/syntax_error_example.rb @@ -0,0 +1,7 @@ +describe "when passing a block to a matcher" do + it "you should use {} instead of do/end" do + Object.new.should satisfy do + "this block is being passed to #should instead of #satisfy - use {} instead" + end + end +end diff --git a/vendor/plugins/rspec/failing_examples/team_spec.rb b/vendor/plugins/rspec/failing_examples/team_spec.rb new file mode 100644 index 000000000..41a44e551 --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/team_spec.rb @@ -0,0 +1,44 @@ +require File.dirname(__FILE__) + '/spec_helper' + + +class Team + attr_reader :players + def initialize + @players = Players.new + end +end + +class Players + def initialize + @players = [] + end + def size + @players.size + end + def include? player + raise "player must be a string" unless player.is_a?(String) + @players.include? player + end +end + +describe "A new team" do + + before(:each) do + @team = Team.new + end + + it "should have 3 players (failing example)" do + @team.should have(3).players + end + + it "should include some player (failing example)" do + @team.players.should include("Some Player") + end + + it "should include 5 (failing example)" do + @team.players.should include(5) + end + + it "should have no players" + +end diff --git a/vendor/plugins/rspec/failing_examples/timeout_behaviour.rb b/vendor/plugins/rspec/failing_examples/timeout_behaviour.rb new file mode 100644 index 000000000..18221365f --- /dev/null +++ b/vendor/plugins/rspec/failing_examples/timeout_behaviour.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe "Something really slow" do + it "should be failed by RSpec when it takes longer than --timeout" do + sleep(2) + end +end |