Sha256: 59c59ff16a81126aaaa8ca949febe559fad242791be11c2dceaf7bff623bb7e2

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

module Padrino
  module Generators
    module Components
      module Tests

        module RiotGen
          RIOT_SETUP = (<<-TEST).gsub(/^ {10}/, '')
          class Riot::Situation
            include Rack::Test::Methods

            def app
              CLASS_NAME.tap { |app| app.set :environment, :test }
            end
          end
          TEST

          def setup_test
            require_dependencies 'riot', :only => :testing
            insert_test_suite_setup RIOT_SETUP
          end

          RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
          require File.dirname(__FILE__) + '/../test_config.rb'

          context "!NAME!Controller" do
            context "description here" do
              setup { get '/' }
              asserts("the response body") { last_response.body }.equals "Hello World"
            end
          end
          TEST

          # Generates a controller test given the controllers name
          def generate_controller_test(name)
            riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
            create_file destination_root("test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
          end

          RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
          require File.dirname(__FILE__) + '/../test_config.rb'

          context "!NAME! Model" do
            context 'can be created' do
              setup { @!DNAME! = !NAME!.new }
              asserts("that record is not nil") { !@!DNAME!.nil? }
            end
          end
          TEST

          def generate_model_test(name)
            riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
            create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), riot_contents, :skip => true
          end

        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
padrino-gen-0.7.3 lib/padrino-gen/generators/components/tests/riot_test_gen.rb
padrino-gen-0.7.2 lib/padrino-gen/generators/components/tests/riot_test_gen.rb
padrino-gen-0.7.1 lib/padrino-gen/generators/components/tests/riot_test_gen.rb
padrino-gen-0.7.0 lib/padrino-gen/generators/components/tests/riot_test_gen.rb
padrino-gen-0.6.7 lib/padrino-gen/generators/components/tests/riot_test_gen.rb