Class: Graham::DSL
- Inherits:
-
Mallow::BasicDSL
- Object
- Mallow::BasicDSL
- Graham::DSL
- Includes:
- Mallow::DSL::Matchers
- Defined in:
- lib/graham/dsl.rb
Class Method Summary collapse
Instance Method Summary collapse
- #does_not_raise(x = nil) ⇒ Object (also: #returns_, #does_not_raise_a, #does_not_raise_an, #does_not_raise_an_exception)
-
#initialize(ns) ⇒ DSL
constructor
A new instance of DSL.
- #method_missing(msg, *args, &b) ⇒ Object
- #raises(x = nil) ⇒ Object (also: #raises_an, #raises_a, #raises_an_exception)
-
#subject(obj) ⇒ Object
(also: #[])
Specify the subject for the next test.
-
#where(&b) ⇒ Object
(also: #is_such_that, #such_that, #that, #and)
Add a condition on a test case’s return value.
Constructor Details
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
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 |