Sha256: efe164f16708c637dfe1651de0eb1107fb8269484b2c05b6b69f46f4e87db987

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'
require 'generator_spec'
require 'generators/smashing_documentation/install_generator'
RSpec.describe SmashingDocumentation::Generators::InstallGenerator, type: :generator do
  let(:rails_helper) { "spec/rails_helper.rb" }
  let(:spec_helper) { "spec/spec_helper.rb" }
  let(:docs_template) { "smashing_docs/template.md" }
  context "when rspec is installed" do
    describe "#update_spec_helper" do
      it "appends the SmashingDocs config to rails_helper.rb" do
        run_generator
        expect(File).to exist(rails_helper)
        expect(File.read(rails_helper)).to include("SmashingDocs.config do")
      end

      it "appends test suite hooks inside RSpec.configure block in spec_helper.rb" do
        run_generator
        expect(File).to exist(spec_helper)
        expect(File.read(spec_helper)).to include("config.after(:each,")
        expect(File.read(spec_helper)).to include("config.after(:suite)")
      end
    end

    describe "#generate_docs_template" do
      it "generates the default docs template" do
        run_generator
        expect(File).to exist(docs_template)
        expect(File.read(docs_template)).to include("request.method")
        expect(File.read(docs_template)).to include("response.body")
      end
    end
  end
  context "when rspec is not installed" do
    it "does not install smashing_docs" do
      `rm -f "#{rails_helper}"`
      File.rename('spec', 's') if Dir.exists?('spec')
      run_generator
      File.rename('s', 'spec') if Dir.exists?('s')
      expect(File).to_not exist(rails_helper)

      # STDOUT is not tested here because it is suppressed in generator tests
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smashing_docs-1.1.0 gem_rspec/install_generator_spec.rb