Module: RSpec::Generator

Defined in:
lib/rspec_for_generators/generator_spec_helper.rb,
lib/rspec_for_generators/matchers/helpers/file.rb

Defined Under Namespace

Modules: Helpers

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.generatorObject

Returns the value of attribute generator.



28
29
30
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 28

def generator
  @generator
end

.test_method_nameObject

Returns the value of attribute test_method_name.



28
29
30
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 28

def test_method_name
  @test_method_name
end

Class Method Details

.check(&block) ⇒ Object



56
57
58
59
60
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 56

def check(&block)
  if block
    block.arity < 1 ? self.instance_eval(&block) : block.call(self)  
  end      
end

.configure_root_dir(path, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 34

def configure_root_dir path, options = {}
  ::Rails.application.configure do
    config.root_dir = options == :custom ? TmpRails.root_dir(File.dirname(path) + '/../tmp', :custom) : TmpRails.root_dir(path)
  end

  ::RSpec::Generators::TestCase.destination ::Rails.root      
  ::Rails::Generators.configure! 
  
  ::RSpec.configure do |config|
    config.after(:suite) do
      ::RSpec::Generator.remove_rails_dir!
    end
  end        
end

.remove_rails_dir!Object



30
31
32
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 30

def remove_rails_dir!
  FileUtils.rm_rf ::TmpRails.root
end

.run_generator(*args, &block) ⇒ Object



49
50
51
52
53
54
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 49

def run_generator *args, &block
  generator.run_generator *args
  if block
    block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self)  
  end      
end

.setup_generator(test_method_name = nil, &block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 72

def setup_generator test_method_name=nil, &block
  clean! if test_method_name  
  generator = get_generator(test_method_name).extend(RSpec::Generator::Helpers)
  if block
    block.arity < 1 ? generator.class.instance_eval(&block) : block.call(generator.class)  
  end
end

.with(generator, &block) ⇒ Object



62
63
64
65
66
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 62

def with(generator, &block)
  if block
    block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self, generator.class)  
  end
end

.with_generator(&block) ⇒ Object



68
69
70
# File 'lib/rspec_for_generators/generator_spec_helper.rb', line 68

def with_generator &block
  with(get_generator, &block)
end