Sha256: 2f234dec771aacf3c6b2d402059d617c78cd984ef0a28c1daeb0b08b6f328d3a

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

require 'rails/generators/ripple_generator'

module Ripple
  module Generators
    class TestGenerator < Base
      desc 'Generates test helpers for Ripple. Test::Unit, RSpec and Cucumber are supported.'
      # Cucumber
      def create_cucumber_file
        if File.directory?("features/support")
          template 'cucumber.rb.erb', 'features/support/ripple.rb'
        end
      end

      # RSpec
      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#{indentation}  config.after(:suite) { Ripple::TestServer.instance.stop }\n"
          end
        end
      end

      # Test::Unit
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wyngle-ripple-0.1.0 lib/rails/generators/ripple/test/test_generator.rb