Module: StaticMock
- Defined in:
- lib/static_mock.rb,
lib/static_mock/version.rb
Defined Under Namespace
Classes: StepDefinitionError
Constant Summary
collapse
- OUTPUT_DIR =
File.join(Dir.tmpdir, '/static_mock')
- VERSION =
"0.1.0"
- @@steps =
[]
- @@mocks =
[]
Class Method Summary
collapse
Class Method Details
.define_step(step_name, &block) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/static_mock.rb', line 22
def self.define_step(step_name, &block)
raise StepDefinitionError if block.nil?
step_out_file = File.join(OUTPUT_DIR, "#{step_name}.yml")
File.delete(step_out_file) if File.exist?(step_out_file)
Step.new(step_name, block).tap { |step| @@steps << step }
end
|
.init ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/static_mock.rb', line 13
def self.init
Object.include(ObjectExtension)
Dir.mkdir(OUTPUT_DIR) unless Dir.exist?(OUTPUT_DIR)
@@steps = []
@@mocks = []
end
|
.load_mocks(step_name) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/static_mock.rb', line 43
def self.load_mocks(step_name)
ret = []
$/="\n\n"
File.open(File.join(OUTPUT_DIR, "#{step_name}.yml"), 'r').each do |obj|
ret << YAML::load(obj)
end
ret
end
|
.mock(*mock_list) ⇒ Object
39
40
41
|
# File 'lib/static_mock.rb', line 39
def self.mock(*mock_list)
@@mocks = mock_list
end
|
.run ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/static_mock.rb', line 31
def self.run
@@steps.each do |step|
step.run
@@mocks.each { |o| o.static_mock(step.step_name, OUTPUT_DIR) }
end
end
|