tests/object.fy in fancy-0.7.0 vs tests/object.fy in fancy-0.8.0
- old
+ new
@@ -213,10 +213,26 @@
arr do: {
is: [2] # same
}
}
+ it: "calls a given block with self if the block takes an argument" with: 'do: when: {
+ arr = []
+ arr do: @{
+ << 1
+ << 2
+ << 3
+ select!: 'even?
+ } . is: [2]
+
+ arr do: @{
+ is: [2] # same
+ }
+
+ 2 do: @{ inspect } . is: 2
+ }
+
it: "calls a given block with the receiver before returning itself" with: 'tap: when: {
10 + 2 tap: |x| {
x is: 12
x is_a?: Number . is: true
} . is: 12
@@ -257,11 +273,11 @@
o2 slots is: $ o1 slots
o2 get_slot: 'slot1 == (o1 slot1) is: true
o2 get_slot: 'slot2 == (o1 slot2) is: true
}
- it: "returns itself when return is send as a message" with: 'return when: {
+ it: "returns itself when return is send as a message" when: {
def foo: array {
array each: @{ return }
}
foo: [1,2,3] . is: 1
@@ -275,11 +291,11 @@
v = []
bar: [1,2,3] values: v . is: 1
v is: [1]
}
- it: "provides temporarily mutable slots" with: 'with_mutable_slots: when: {
+ it: "provides temporarily mutable slots" with: 'with_mutable_slots:do: when: {
class Student {
read_slots: ('name, 'age, 'city)
def initialize: block {
with_mutable_slots: ('name, 'age, 'city) do: block
}
@@ -301,7 +317,65 @@
# no changes
p name is: "Chris"
p age is: 24
p city is: "Osnabrück"
+ }
+
+ it: "ignores all specified exception types" with: 'ignoring:do: when: {
+ {
+ [{ 2 / 0 }, { "foo" unknown_method_on_string! }] each: |b| {
+ ignoring: (ZeroDivisionError, NoMethodError) do: b
+ }
+ } does_not raise: Exception
+ }
+
+ it: "rebinds a singleton method within a block" with: 'rebind_method:with:within: when: {
+ s = "foo"
+ s rebind_method: 'hello with: { 42 } within: {
+ s hello is: 42
+ }
+
+ s rebind_method: 'hello with: 'to_s within: {
+ s hello is: "foo"
+ }
+
+ { s hello } raises: NoMethodError
+
+ def s bar {
+ "bar!"
+ }
+
+ s bar is: "bar!"
+
+ s rebind_method: 'bar with: { "new bar!" } within: {
+ s bar is: "new bar!"
+ }
+
+ s rebind_method: 'bar with: { "another bar!" } within: |x| { x bar } . is: "another bar!"
+
+ s bar is: "bar!"
+ }
+
+ it: "binds a dynvar correctly" with: 'let:be:in:ensuring: when: {
+ *var* is: nil
+ let: '*var* be: 'hello in: {
+ *var* is: 'hello
+ } ensuring: {
+ *var* is: 'hello
+ }
+ *var* is: nil
+
+ @val = nil
+ def check {
+ *var* is: @val
+ }
+
+ check
+ @val = "test"
+ let: '*var* be: @val in: {
+ check
+ }
+ @val = nil
+ check
}
}