Class: NestedScenarios::Builder
- Defined in:
- lib/nested_scenarios/builder.rb
Constant Summary collapse
- @@select_sql =
"SELECT * FROM %s"
Class Method Summary collapse
- .fixture_file_exists? ⇒ Boolean
- .fixtures_dir(*paths) ⇒ Object
- .fixtures_dir_exists?(dir = @scenario) ⇒ Boolean
- .spec_or_test_dir ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(scenario, &block) ⇒ Builder
constructor
A new instance of Builder.
- #names_from_ivars! ⇒ Object
Constructor Details
#initialize(scenario, &block) ⇒ Builder
Returns a new instance of Builder.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nested_scenarios/builder.rb', line 18 def initialize(scenario, &block) case scenario when Hash @scenario = scenario.join('/') when Symbol, String @scenario = scenario.to_s else raise "I don't know how to build `#{scenario.inspect}'" end @block = block @custom_names = {} end |
Class Method Details
.fixture_file_exists? ⇒ Boolean
60 61 62 |
# File 'lib/nested_scenarios/builder.rb', line 60 def self.fixture_file_exists? File.exists? fixture_file end |
.fixtures_dir(*paths) ⇒ Object
48 49 50 |
# File 'lib/nested_scenarios/builder.rb', line 48 def self.fixtures_dir(*paths) File.join(RAILS_ROOT, spec_or_test_dir, 'fixtures', *paths) end |
.fixtures_dir_exists?(dir = @scenario) ⇒ Boolean
56 57 58 |
# File 'lib/nested_scenarios/builder.rb', line 56 def self.fixtures_dir_exists?(dir = @scenario) File.exists? fixtures_dir(dir) end |
.spec_or_test_dir ⇒ Object
52 53 54 |
# File 'lib/nested_scenarios/builder.rb', line 52 def self.spec_or_test_dir File.exists?(File.join(RAILS_ROOT, 'spec')) ? 'spec' : 'test' end |
Instance Method Details
#build ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/nested_scenarios/builder.rb', line 32 def build say "Building scenario `#{@scenario}'" NestedScenarios.delete_tables surface_errors { instance_eval(&@block) } FileUtils.mkdir_p self.class.fixtures_dir(@scenario) dump_tables end |
#names_from_ivars! ⇒ Object
42 43 44 45 46 |
# File 'lib/nested_scenarios/builder.rb', line 42 def names_from_ivars! instance_values.each do |var, value| name(var, value) if value.is_a? ActiveRecord::Base end end |