Class: Ripple::Generators::TestGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/rails/generators/ripple/test/test_generator.rb

Instance Method Summary collapse

Methods inherited from Base

source_root

Instance Method Details

#create_cucumber_fileObject

Cucumber



8
9
10
11
12
# File 'lib/rails/generators/ripple/test/test_generator.rb', line 8

def create_cucumber_file
  if File.directory?("features/support")
    template 'cucumber.rb.erb', 'features/support/ripple.rb'
  end
end

#create_rspec_fileObject

RSpec



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails/generators/ripple/test/test_generator.rb', line 15

def create_rspec_file
  if File.file?('spec/spec_helper.rb')
    rspec_prelude = /\s*R[Ss]pec\.configure do \|config\|/
    indentation = File.binread('spec/spec_helper.rb').match(rspec_prelude)[0].match(/^\s*/)[0]
    inject_into_file 'spec/spec_helper.rb', :before => rspec_prelude do
      "#{indentation}require 'ripple/test_server'\n"
    end
    inject_into_file 'spec/spec_helper.rb', :after => rspec_prelude do
      "\n#{indentation}  config.before(:suite) { Ripple::TestServer.setup }" +
        "\n#{indentation}  config.after(:each) { Ripple::TestServer.clear }\n"
    end
  end
end

#create_test_unit_fileObject

Test::Unit



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails/generators/ripple/test/test_generator.rb', line 30

def create_test_unit_file
  if File.file?('test/test_helper.rb')
    test_case_prelude = /\s*class ActiveSupport::TestCase/
    indentation = File.binread('test/test_helper.rb').match(test_case_prelude)[0].match(/^\s*/)[0]
    inject_into_file "test/test_helper.rb", :before => test_case_prelude do
      "#{indentation}# Setup in-memory test server for Riak\n#{indentation}require 'ripple/test_server'\n\n"
    end
    inject_into_class "test/test_helper.rb", 'ActiveSupport::TestCase' do
      "#{indentation}  setup { Ripple::TestServer.setup }\n#{indentation}  teardown { Ripple::TestServer.clear }\n\n"
    end
  end
end