Class: Graham::DSL

Inherits:
Mallow::BasicDSL
  • Object
show all
Includes:
Mallow::DSL::Matchers
Defined in:
lib/graham/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ns) ⇒ DSL

Returns a new instance of DSL.



10
11
12
13
# File 'lib/graham/dsl.rb', line 10

def initialize(ns)
  @core, @ns = Core.new, ns
  reset!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args, &b) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/graham/dsl.rb', line 15

def method_missing(msg, *args, &b)
  case msg.to_s
  when /^((and|that)_)+(.+)$/
    respond_to?($3)? send($3, *args, &b) : super
  else
    _case @ns, msg, args, b
  end
end

Class Method Details

.build_core(ns) {|dsl = new(ns)| ... } ⇒ Object

Yields:

  • (dsl = new(ns))


5
6
7
8
# File 'lib/graham/dsl.rb', line 5

def self.build_core(ns)
  yield(dsl = new(ns))
  dsl.send(:rule!).core
end

Instance Method Details

#does_not_raise(x = nil) ⇒ Object Also known as: returns_, does_not_raise_a, does_not_raise_an, does_not_raise_an_exception



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/graham/dsl.rb', line 49

def does_not_raise(x=nil)
  push {|tc|
    begin
      tc.go
      true
    rescue x => e
      false
    rescue   => e
      x ? raise(e) : false
    end
  }
end

#raises(x = nil) ⇒ Object Also known as: raises_an, raises_a, raises_an_exception



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/graham/dsl.rb', line 36

def raises(x=nil)
  push {|tc|
    begin
      tc.go
      false
    rescue x => e
      true
    rescue   => e
      x ? raise(e) : true
    end
  }
end

#subject(obj) ⇒ Object Also known as: []

Specify the subject for the next test.



32
33
34
# File 'lib/graham/dsl.rb', line 32

def subject(obj)
  TestCase::Proxy.new self, obj
end

#where(&b) ⇒ Object Also known as: is_such_that, such_that, that, and

Add a condition on a test case’s return value. If the given block has no parameters, it is evaluated in the context of the return value.



27
28
29
# File 'lib/graham/dsl.rb', line 27

def where(&b)
  push {|e| preproc(b).call e.go }
end