Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Showing with 58 additions and 24 deletions.
  1. +39 −20 lib/fancy_spec.fy
  2. +4 −0 lib/rbx/class.fy
  3. +7 −0 lib/rbx/string.fy
  4. +4 −0 lib/rbx/symbol.fy
  5. +1 −1 tests/fixnum.fy
  6. +2 −2 tests/object.fy
  7. +1 −1 tests/tuple.fy
View
59 lib/fancy_spec.fy
@@ -78,14 +78,18 @@ class FancySpec {
"""
test = SpecTest new: spec_info_string block: spec_block
- # try {
- # @test_obj method: method_name . if_true: |method| {
- # method tests << test
- # }
- # } catch MethodNotFoundError => e {
- # # ignore errors
- # }
+
@spec_tests << test
+
+ match @test_obj {
+ case Class ->
+ has_method? = @test_obj has_method?: method_name
+ { has_method? = @test_obj metaclass has_method?: method_name } unless: has_method?
+
+ unless: has_method? do: {
+ SpecTest method_not_found: method_name for: @test_obj
+ }
+ }
}
alias_method: 'it:for:when: for: 'it:with:when:
@@ -144,6 +148,7 @@ class FancySpec {
@@failed_count = 0
@@total_tests = 0
@@total_expectations = 0
+ @@methods_not_found = <[]>
def SpecTest add_expectation {
@@total_expectations = @@total_expectations + 1
@@ -173,29 +178,43 @@ class FancySpec {
@@failed_count = @@failed_count + 1
}
+ def SpecTest method_not_found: method_name for: type {
+ { @@methods_not_found[type]: []} unless: $ @@methods_not_found[type]
+ @@methods_not_found[type] << method_name
+ }
+
def SpecTest current {
@@current
}
def SpecTest print_failures: start_time no_failures: ok_block else: error_block {
- @@failed_positive each: |test_obj failed_tests| {
- failed_tests each: |t| {
- Console newline
- "> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
- t print_failed_positive
+ let: '*stdout* be: *stderr* in: {
+ @@failed_positive each: |test_obj failed_tests| {
+ failed_tests each: |t| {
+ "\n> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
+ t print_failed_positive
+ }
}
- }
- @@failed_negative each: |test_obj failed_tests| {
- failed_tests each: |t| {
- Console newline
- "> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
- t print_failed_negative
+ @@failed_negative each: |test_obj failed_tests| {
+ failed_tests each: |t| {
+ "\n> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
+ t print_failed_negative
+ }
}
+
+ unless: (@@methods_not_found empty? ) do: {
+ "The following methods were referenced in tests but could not be found:" println
+ max_size = @@methods_not_found keys map: @{ to_s size } . max
+ @@methods_not_found each: |type, methods| {
+ *stdout* printf("%-#{max_size}s : ", type)
+ methods map: @{ to_fancy_message } . join: ", " . println
+ }
+ }
+
+ "\nRan #{@@total_tests} tests (#{@@total_expectations} expectations) with #{@@failed_count} failures in #{Time now - start_time} seconds." println
}
- Console newline
- "Ran #{@@total_tests} tests (#{@@total_expectations} expectations) with #{@@failed_count} failures in #{Time now - start_time} seconds." println
if: (@@failed_count == 0) then: ok_block else: error_block
}
View
4 lib/rbx/class.fy
@@ -133,6 +133,10 @@ class Class {
instance_method(name message_name)
}
+ def has_method?: method_name {
+ lookup_method(method_name message_name) nil? not
+ }
+
def alias_method_rbx: new_method_name for: old_method_name {
"""
Rbx specific version of alias_method:for: due to bootstrap order
View
7 lib/rbx/string.fy
@@ -167,4 +167,11 @@ class String {
def message_name {
self to_sym message_name to_s
}
+
+ def to_fancy_message {
+ match self {
+ case /^:/ -> rest to_sym
+ case _ -> self
+ }
+ }
}
View
4 lib/rbx/symbol.fy
@@ -32,4 +32,8 @@ class Symbol {
case false -> ":" <<(symbol) to_sym
}
}
+
+ def to_fancy_message {
+ to_s to_fancy_message to_sym
+ }
}
View
2 tests/fixnum.fy
@@ -118,7 +118,7 @@ FancySpec describe: Fixnum with: {
sum is: ((10..19) sum)
}
- it: "tries to run a code block self amount of times or fails" with: 'try_times: when: {
+ it: "tries to run a code block self amount of times or fails" with: 'times_try: when: {
{ -2 times_try: { 2 / 0 } } does_not raise: Exception
{ -1 times_try: { 2 / 0 } } does_not raise: Exception
{ 0 times_try: { 2 / 0 } } does_not raise: Exception
View
4 tests/object.fy
@@ -275,7 +275,7 @@ FancySpec describe: Object with: {
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 }
}
@@ -293,7 +293,7 @@ FancySpec describe: Object with: {
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 {
View
2 tests/tuple.fy
@@ -37,7 +37,7 @@ FancySpec describe: Tuple with: {
{ Tuple new: 2 } does_not raise: ArgumentError
}
- it: "creates tuples dynamically" with: 'with_values when: {
+ it: "creates tuples dynamically" with: 'with_values: when: {
Tuple with_values: [1,2,3] . is: (1,2,3)
Tuple with_values: ["foo",'bar,42] . is: ("foo", 'bar, 42)
Tuple with_values: ('hello, 'world) . is: ('hello, 'world)

No commit comments for this range

Something went wrong with that request. Please try again.