summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/example_spec.rb
blob: b4391f802db6871c7867c28d5d52bb49c5f7a90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'spec_helper'
require 'mspec/matchers/base'
require 'mspec/runner/mspec'
require 'mspec/mocks/mock'
require 'mspec/runner/example'

describe ExampleState do
  it "is initialized with the ContextState, #it string, and #it block" do
    prc = lambda { }
    context = ContextState.new ""
    ExampleState.new(context, "does", prc).should be_kind_of(ExampleState)
  end
end

describe ExampleState, "#describe" do
  before :each do
    @context = ContextState.new Object, "#to_s"
    @state = ExampleState.new @context, "it"
  end

  it "returns the ContextState#description" do
    @state.describe.should == @context.description
  end
end

describe ExampleState, "#it" do
  before :each do
    @state = ExampleState.new ContextState.new("describe"), "it"
  end

  it "returns the argument to the #it block" do
    @state.it.should == "it"
  end
end

describe ExampleState, "#context=" do
  before :each do
    @state = ExampleState.new ContextState.new("describe"), "it"
    @context = ContextState.new "New#context"
  end

  it "sets the containing ContextState" do
    @state.context = @context
    @state.context.should == @context
  end

  it "resets the description" do
    @state.description.should == "describe it"
    @state.context = @context
    @state.description.should == "New#context it"
  end
end

describe ExampleState, "#example" do
  before :each do
    @proc = lambda { }
    @state = ExampleState.new ContextState.new("describe"), "it", @proc
  end

  it "returns the #it block" do
    @state.example.should == @proc
  end
end

describe ExampleState, "#filtered?" do
  before :each do
    MSpec.store :include, nil
    MSpec.store :exclude, nil

    @state = ExampleState.new ContextState.new("describe"), "it"
    @filter = double("filter")
  end

  after :each do
    MSpec.store :include, nil
    MSpec.store :exclude, nil
  end

  it "returns false if MSpec include filters list is empty" do
    @state.filtered?.should == false
  end

  it "returns false if MSpec include filters match this spec" do
    @filter.should_receive(:===).and_return(true)
    MSpec.register :include, @filter
    @state.filtered?.should == false
  end

  it "returns true if MSpec include filters do not match this spec" do
    @filter.should_receive(:===).and_return(false)
    MSpec.register :include, @filter
    @state.filtered?.should == true
  end

  it "returns false if MSpec exclude filters list is empty" do
    @state.filtered?.should == false
  end

  it "returns false if MSpec exclude filters do not match this spec" do
    @filter.should_receive(:===).and_return(false)
    MSpec.register :exclude, @filter
    @state.filtered?.should == false
  end

  it "returns true if MSpec exclude filters match this spec" do
    @filter.should_receive(:===).and_return(true)
    MSpec.register :exclude, @filter
    @state.filtered?.should == true
  end

  it "returns true if MSpec include and exclude filters match this spec" do
    @filter.should_receive(:===).twice.and_return(true)
    MSpec.register :include, @filter
    MSpec.register :exclude, @filter
    @state.filtered?.should == true
  end
end