tests/object.fy in fancy-0.3.2 vs tests/object.fy in fancy-0.3.3

- old
+ new

@@ -1,14 +1,14 @@ FancySpec describe: Object with: { it: "should dynamically evaluate a message-send with no arguments" when: { obj = 42 - obj send: "to_s" . should == "42" + obj send_message: 'to_s . should == "42" } it: "should dynamically evaluate a message-send with a list of arguments" when: { obj = "hello, world" - obj send: "from:to:" params: [0,4] . should == "hello" + obj send_message: 'from:to: with_params: [0,4] . should == "hello" } it: "should dynamically define slotvalues" when: { obj = Object new obj get_slot: 'foo . should == nil @@ -20,15 +20,11 @@ def self a_singleton_method { "a singleton method!" } self a_singleton_method should == "a singleton method!" self undefine_singleton_method: 'a_singleton_method - try { - self a_singleton_method should == nil # should not get here - } catch NoMethodError => e { - e method_name should == "a_singleton_method" - } + { self a_singleton_method } should raise: NoMethodError } it: "should return its class" when: { nil class should == NilClass true class should == TrueClass @@ -77,57 +73,80 @@ } # boolean messages it: "should be true for calling and: with non-nil values" for: 'and: when: { - 'foo and: 'bar . should == true + 'foo and: 'bar . should == 'bar } it: "should be false for calling and: with a nil value" for: 'and: when: { - 'foo and: nil . should == false + 'foo and: nil . should == nil } it: "should be true for calling && with non-nil values" for: '&& when: { - ('foo && 'bar) should == true + ('foo && 'bar) should == 'bar } it: "should be false for calling && with a nil value" for: '&& when: { - ('foo && nil) should == false + ('foo && nil) should == nil } it: "should be true for calling or: with any value" for: 'or: when: { - 'foo or: 'bar . should == true - 'foo or: nil . should == true + 'foo or: 'bar . should == 'foo + 'foo or: nil . should == 'foo } it: "should be true for calling || with any value" for: '|| when: { ('foo || 'bar) should == 'foo ('foo || nil) should == 'foo } # end boolean messages it: "should NOT be nil for non-nil values" for: 'nil? when: { - 'foo nil? should == nil - 1 nil? should == nil - "hello" nil? should == nil + 'foo nil? should == false + 1 nil? should == false + "hello" nil? should == false } it: "should NOT be false for non-nil values" for: 'false? when: { - 'foo false? should == nil - "hello, world" false? should == nil + 'foo false? should == false + "hello, world" false? should == false } it: "should not be true" for: 'true? when: { - 'foo true? should == nil - "hello, world" true? should == nil + 'foo true? should == false + "hello, world" true? should == false } it: "should return the correct value" for: 'returning:do: when: { returning: [] do: |arr| { arr << 1 arr << 2 arr << 3 } . should == [1,2,3] + } + + it: "should only call a method if the receiver responds to it using a RespondsToProxy" for: 'if_responds? when: { + class SomeClass { + def some_method { + 'it_works! + } + } + + s = SomeClass new + s if_responds? some_method should == 'it_works! + s if_responds? some_undefined_method should == nil + } + + it: "should call the backtick: method when using the '`' syntax" for: 'backtick: when: { + `cat #{__FILE__}` should == (File read: __FILE__) + + # override backticks + def backtick: str { + str + " - NOT!" + } + + `ls -al` should == "ls -al - NOT!" } }