aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/lib/mspec/runner/example.rb
blob: 19eb29b0791afbafd6a3426828ccf0c9e52b222d (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
require 'mspec/runner/mspec'

# Holds some of the state of the example (i.e. +it+ block) that is
# being evaluated. See also +ContextState+.
class ExampleState
  attr_reader   :context, :it, :example

  def initialize(context, it, example=nil)
    @context  = context
    @it       = it
    @example  = example
  end

  def context=(context)
    @description = nil
    @context = context
  end

  def describe
    @context.description
  end

  def description
    @description ||= "#{describe} #{@it}"
  end

  def filtered?
    incl = MSpec.retrieve(:include) || []
    excl = MSpec.retrieve(:exclude) || []
    included   = incl.empty? || incl.any? { |f| f === description }
    included &&= excl.empty? || !excl.any? { |f| f === description }
    !included
  end
end