changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/heckle_runner_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2unless [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM}
3 require 'spec/runner/heckle_runner'
4
5 module Foo
6 class Bar
7 def one; end
8 def two; end
9 end
10
11 class Zap
12 def three; end
13 def four; end
14 end
15 end
16
17 describe "HeckleRunner" do
18 before(:each) do
19 @heckle = mock("heckle", :null_object => true)
20 @heckle_class = mock("heckle_class")
21 end
22
23 it "should heckle all methods in all classes in a module" do
24 @heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
25 @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
26 @heckle_class.should_receive(:new).with("Foo::Zap", "three", rspec_options).and_return(@heckle)
27 @heckle_class.should_receive(:new).with("Foo::Zap", "four", rspec_options).and_return(@heckle)
28
29 heckle_runner = Spec::Runner::HeckleRunner.new("Foo", @heckle_class)
30 heckle_runner.heckle_with
31 end
32
33 it "should heckle all methods in a class" do
34 @heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
35 @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
36
37 heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar", @heckle_class)
38 heckle_runner.heckle_with
39 end
40
41 it "should fail heckling when the class is not found" do
42 lambda do
43 heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bob", @heckle_class)
44 heckle_runner.heckle_with
45 end.should raise_error(StandardError, "Heckling failed - \"Foo::Bob\" is not a known class or module")
46 end
47
48 it "should heckle specific method in a class (with #)" do
49 @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
50
51 heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar#two", @heckle_class)
52 heckle_runner.heckle_with
53 end
54
55 it "should heckle specific method in a class (with .)" do
56 @heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
57
58 heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar.two", @heckle_class)
59 heckle_runner.heckle_with
60 end
61 end
62
63 describe "Heckler" do
64 it "should say yes to tests_pass? if specs pass" do
65 options = mock("options", :null_object => true)
66 options.should_receive(:run_examples).and_return(true)
67 heckler = Spec::Runner::Heckler.new("Foo", nil, options)
68 heckler.tests_pass?.should be_true
69 end
70
71 it "should say no to tests_pass? if specs fail" do
72 options = mock("options", :null_object => true)
73 options.should_receive(:run_examples).and_return(false)
74 heckler = Spec::Runner::Heckler.new("Foo", nil, options)
75 heckler.tests_pass?.should be_false
76 end
77 end
78end