Class: Marso::ScenarioFactory

Inherits:
Object
  • Object
show all
Includes:
BaseFactory
Defined in:
lib/marso/domain/scenario/scenario_factory.rb

Instance Method Summary collapse

Instance Method Details

#create_scenario_file(description = {}, root = nil) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/marso/domain/scenario/scenario_factory.rb', line 12

def create_scenario_file(description={}, root=nil)
	raise ArgumentError, "Scenario's name is required" unless description[:name]
	id = description[:id] || SecureRandom.hex(3)
	name = description[:name]
	given = description[:given] || ""
	_when = description[:when] || ""
	_then = description[:then] || ""

	template = get_template(Pathname("../scenario_template.rb").expand_path(__FILE__))
		.gsub(/#\{id\}/, id)
		.gsub(/#\{name\}/, name)
		.gsub(/#\{given\}/, given)
		.gsub(/#\{_when\}/, _when)
		.gsub(/#\{_then\}/, _then)

	fname = name.downcase.gsub(' ', '_')
	feature_file = "#{fname}.rb"
	root = root || Dir.pwd

	dest = File.join(root, feature_file)
	File.open(dest, "w") do |f|
		f.write(template)
	end

	return feature_file
end