Reduce nesting by collapsing modules with ::

This commit is contained in:
Michael Miller 2018-09-27 16:20:55 -06:00
parent 0d282d3d50
commit 77b4c71c2a
14 changed files with 440 additions and 468 deletions

View file

@ -1,5 +1,4 @@
module Spectator module Spectator::DSL
module DSL
module Builder module Builder
extend self extend self
@ -61,5 +60,4 @@ module Spectator
root_group.build(nil, Internals::SampleValues.empty) root_group.build(nil, Internals::SampleValues.empty)
end end
end end
end
end end

View file

@ -1,7 +1,6 @@
require "./matcher_dsl" require "./matcher_dsl"
module Spectator module Spectator::DSL
module DSL
module ExampleDSL module ExampleDSL
include MatcherDSL include MatcherDSL
@ -13,5 +12,4 @@ module Spectator
::Spectator::Expectation.new({{actual.stringify}}, {{actual}}) ::Spectator::Expectation.new({{actual.stringify}}, {{actual}})
end end
end end
end
end end

View file

@ -1,5 +1,4 @@
module Spectator module Spectator::DSL
module DSL
class ExampleFactory class ExampleFactory
def initialize(@example_type : Example.class) def initialize(@example_type : Example.class)
end end
@ -8,5 +7,4 @@ module Spectator
@example_type.new(group, sample_values) @example_type.new(group, sample_values)
end end
end end
end
end end

View file

@ -1,5 +1,4 @@
module Spectator module Spectator::DSL
module DSL
class ExampleGroupBuilder class ExampleGroupBuilder
alias Child = ExampleFactory | ExampleGroupBuilder alias Child = ExampleFactory | ExampleGroupBuilder
@ -56,5 +55,4 @@ module Spectator
) )
end end
end end
end
end end

View file

@ -1,7 +1,6 @@
require "./example_group_builder" require "./example_group_builder"
module Spectator module Spectator::DSL
module DSL
class GivenExampleGroupBuilder(T) < ExampleGroupBuilder class GivenExampleGroupBuilder(T) < ExampleGroupBuilder
def initialize(what : String, @collection : Array(T), @symbol : Symbol) def initialize(what : String, @collection : Array(T), @symbol : Symbol)
@ -25,5 +24,4 @@ module Spectator
end end
end end
end end
end
end end

View file

@ -1,11 +1,9 @@
require "../matchers" require "../matchers"
module Spectator module Spectator::DSL
module DSL
module MatcherDSL module MatcherDSL
macro eq(expected) macro eq(expected)
::Spectator::Matchers::EqualityMatcher.new({{expected.stringify}}, {{expected}}) ::Spectator::Matchers::EqualityMatcher.new({{expected.stringify}}, {{expected}})
end end
end end
end
end end

View file

@ -1,7 +1,6 @@
require "../example_group" require "../example_group"
module Spectator module Spectator::DSL
module DSL
module StructureDSL module StructureDSL
def initialize(sample_values : Internals::SampleValues) def initialize(sample_values : Internals::SampleValues)
@ -196,5 +195,4 @@ module Spectator
end end
end end
end end
end
end end

View file

@ -1,8 +1,7 @@
require "./formatter" require "./formatter"
require "colorize" require "colorize"
module Spectator module Spectator::Formatters
module Formatters
class DefaultFormatter < Formatter class DefaultFormatter < Formatter
SUCCESS_COLOR = :green SUCCESS_COLOR = :green
FAILURE_COLOR = :red FAILURE_COLOR = :red
@ -116,5 +115,4 @@ module Spectator
return sprintf("%i days %i:%02i:%02i", days, hours, minutes, int_seconds) return sprintf("%i days %i:%02i:%02i", days, hours, minutes, int_seconds)
end end
end end
end
end end

View file

@ -1,10 +1,8 @@
module Spectator module Spectator::Formatters
module Formatters
abstract class Formatter abstract class Formatter
abstract def start_suite abstract def start_suite
abstract def end_suite(results : TestResults) abstract def end_suite(results : TestResults)
abstract def start_example(example : Example) abstract def start_example(example : Example)
abstract def end_example(result : Result) abstract def end_example(result : Result)
end end
end
end end

View file

@ -1,7 +1,6 @@
require "./value_wrapper" require "./value_wrapper"
module Spectator module Spectator::Internals
module Internals
struct SampleValues struct SampleValues
private record Entry, name : String, wrapper : ValueWrapper private record Entry, name : String, wrapper : ValueWrapper
@ -23,5 +22,4 @@ module Spectator
@values[id].wrapper @values[id].wrapper
end end
end end
end
end end

View file

@ -1,12 +1,10 @@
require "./value_wrapper" require "./value_wrapper"
module Spectator module Spectator::Internals
module Internals
class TypedValueWrapper(T) < ValueWrapper class TypedValueWrapper(T) < ValueWrapper
getter value : T getter value : T
def initialize(@value : T) def initialize(@value : T)
end end
end end
end
end end

View file

@ -1,5 +1,4 @@
module Spectator module Spectator::Internals
module Internals
# Base class for proxying test values to examples. # Base class for proxying test values to examples.
# This abstraction is required for inferring types. # This abstraction is required for inferring types.
# The `DSL#let` macro makes heavy use of this. # The `DSL#let` macro makes heavy use of this.
@ -7,5 +6,4 @@ module Spectator
# Retrieves the underlying value. # Retrieves the underlying value.
abstract def value abstract def value
end end
end
end end

View file

@ -1,7 +1,6 @@
require "./matcher" require "./matcher"
module Spectator module Spectator::Matchers
module Matchers
class EqualityMatcher(T) < Matcher class EqualityMatcher(T) < Matcher
def initialize(label, @expected : T) def initialize(label, @expected : T)
super(label) super(label)
@ -19,5 +18,4 @@ module Spectator
"Expected #{expectation.label} to not equal #{label} (using ==)" "Expected #{expectation.label} to not equal #{label} (using ==)"
end end
end end
end
end end

View file

@ -1,5 +1,4 @@
module Spectator module Spectator::Matchers
module Matchers
abstract class Matcher abstract class Matcher
private getter label : String private getter label : String
@ -10,5 +9,4 @@ module Spectator
abstract def message(expectation : Expectation) : String abstract def message(expectation : Expectation) : String
abstract def negated_message(expectation : Expectation) : String abstract def negated_message(expectation : Expectation) : String
end end
end
end end