summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/runner/example.rb
blob: 0d9f0d618c74b0c84d445ebdfb9243866d2b0d7a (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.include
    excl = MSpec.exclude
    included   = incl.empty? || incl.any? { |f| f === description }
    included &&= excl.empty? || !excl.any? { |f| f === description }
    !included
  end
end