Sha256: bda069f614501f85a357a4f4425f98385c794c1678762ddb19f8ef59eff231ab

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

require "fileutils"
require "raml-rb"

require "rambo/rspec/spec_file"
require "rambo/rspec/helper_file"

module Rambo
  class DocumentGenerator
    attr_accessor :file, :raml, :options

    class << self
      def generate!(file, options={})
        generator = new(file, options)
        generator.generate_spec_dir!
        generator.generate_matcher_dir!
        generator.generate_examples!
        generator.generate_spec_file!
        generator.generate_rambo_helper!
        generator.generate_matchers!
      end
    end

    def initialize(file, options={})
      @file    = file
      @raml    = Raml::Parser.parse_file(file)
      @options = options
    end

    def generate_spec_dir!
      FileUtils.mkdir_p("spec/contract/output")
    end

    def generate_examples!
      FileUtils.mkdir_p("spec/support/examples")
    end

    def generate_spec_file!
      spec_file_name = file.match(/[^\/]*\.raml$/).to_s.gsub(/\.raml$/, "_spec.rb")
      contents       = Rambo::RSpec::SpecFile.new(raml, options).render
      File.write("spec/contract/#{spec_file_name}", contents)
    end

    def generate_rambo_helper!
      Rambo::RSpec::HelperFile.new(
        template_path: File.expand_path("../rspec/templates/rambo_helper_file_template.erb", __FILE__),
        file_path: "spec/rambo_helper.rb"
      ).generate
    end

    def generate_matcher_dir!
      FileUtils.mkdir_p("spec/support/matchers")
    end

    def generate_matchers!
      Rambo::RSpec::HelperFile.new(
        template_path: File.expand_path("../rspec/templates/matcher_file_template.erb", __FILE__),
        file_path: "spec/support/matchers/rambo_matchers.rb"
      ).generate
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rambo_ruby-0.3.0 lib/rambo/document_generator.rb
rambo_ruby-0.2.3 lib/rambo/document_generator.rb
rambo_ruby-0.2.2 lib/rambo/document_generator.rb
rambo_ruby-0.2.1 lib/rambo/document_generator.rb
rambo_ruby-0.2.0 lib/rambo/document_generator.rb