Module: MountainBerryFields::Test::Strategy

Included in:
AlwaysFail, AlwaysPass
Defined in:
lib/mountain_berry_fields/test.rb

Overview

You want to run tests, amirite? So you need something that runs them. Right now that’s called a strategy (expect that to change). Strategies take the code to test as a string, and then test them and return if they pass or fail.

Strategies should probably be registered so that the evaluator can find them.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#code_to_testObject (readonly)

Returns the value of attribute code_to_test.



50
51
52
# File 'lib/mountain_berry_fields/test.rb', line 50

def code_to_test
  @code_to_test
end

Class Method Details

.for(name) ⇒ Object



32
33
34
35
36
# File 'lib/mountain_berry_fields/test.rb', line 32

def self.for(name)
  @registered.fetch name.to_s do
    raise NameError, "#{name.inspect} is not a registered strategy, should have been in #{@registered.keys.inspect}"
  end
end

.register(name, strategy) ⇒ Object



38
39
40
# File 'lib/mountain_berry_fields/test.rb', line 38

def self.register(name, strategy)
  @registered[name.to_s] = strategy
end

.registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/mountain_berry_fields/test.rb', line 46

def self.registered?(name)
  @registered.has_key? name.to_s
end

.unregister(name) ⇒ Object



42
43
44
# File 'lib/mountain_berry_fields/test.rb', line 42

def self.unregister(name)
  @registered.delete name.to_s
end

Instance Method Details

#failure_messageObject



60
61
62
# File 'lib/mountain_berry_fields/test.rb', line 60

def failure_message
  raise "unimplemented"
end

#initialize(code_to_test) ⇒ Object



52
53
54
# File 'lib/mountain_berry_fields/test.rb', line 52

def initialize(code_to_test)
  @code_to_test = code_to_test.to_s
end

#pass?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/mountain_berry_fields/test.rb', line 56

def pass?
  raise "unimplemented"
end