summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/example_spec.rb
blob: 8bac166da8d5a228028e29843882fb429654aa36 (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'

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

RSpec.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
    expect(@state.describe).to eq(@context.description)
  end
end

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

  it "returns the argument to the #it block" do
    expect(@state.it).to eq("it")
  end
end

RSpec.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
    expect(@state.context).to eq(@context)
  end

  it "resets the description" do
    expect(@state.description).to eq("describe it")
    @state.context = @context
    expect(@state.description).to eq("New#context it")
  end
end

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

  it "returns the #it block" do
    expect(@state.example).to eq(@proc)
  end
end

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

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

  after :each do
    MSpec.store :include, []
    MSpec.store :exclude, []
  end

  it "returns false if MSpec include filters list is empty" do
    expect(@state.filtered?).to eq(false)
  end

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

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

  it "returns false if MSpec exclude filters list is empty" do
    expect(@state.filtered?).to eq(false)
  end

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

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

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