File: generator_example_group_spec.rb

package info (click to toggle)
ruby-ammeter 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 312 kB
  • sloc: ruby: 703; makefile: 4
file content (66 lines) | stat: -rw-r--r-- 2,576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require "spec_helper"

module Ammeter::RSpec::Rails
  describe GeneratorExampleGroup do
    it { is_expected.to be_included_in_files_in('./spec/generators/') }
    it { is_expected.to be_included_in_files_in('.\\spec\\generators\\') }

    let(:group_class) do
      ::RSpec::Core::ExampleGroup.describe do
        include GeneratorExampleGroup
      end
    end

    it "adds :type => :generator to the metadata" do
      expect(group_class.metadata[:type]).to eq(:generator)
    end

    describe 'an instance of the group' do
      let(:group)     { group_class.new }
      describe 'uses the generator as the implicit subject' do
        let(:generator) { double('generator') }
        it 'sets a generator as subject' do
          allow(group).to receive(:generator).and_return(generator)
          expect(group.subject).to eq generator
        end
      end

      it "allows you to override with explicity subject" do
        group_class.subject { 'explicit' }
        expect(group.subject).to eq 'explicit'
      end

      it 'allows delegation of destination root to ::Rails::Generators::TestCase' do
        group.destination '/some/path'
        expect(group.destination_root).to eq '/some/path'
      end

      describe 'working with files' do
        let(:path_to_gem_root_tmp) { File.expand_path(__FILE__ + '../../../../../../../../tmp') }
        before do
          group.destination path_to_gem_root_tmp
          FileUtils.rm_rf path_to_gem_root_tmp
          FileUtils.mkdir path_to_gem_root_tmp
        end
        it 'should use destination to find relative root file' do
          expect(group.file('app/model/post.rb')).to eq "#{path_to_gem_root_tmp}/app/model/post.rb"
        end

        describe 'migrations' do
          before do
            tmp_db_migrate = path_to_gem_root_tmp + '/db/migrate'
            FileUtils.mkdir_p tmp_db_migrate
            FileUtils.touch(tmp_db_migrate + '/20111010200000_create_comments.rb')
            FileUtils.touch(tmp_db_migrate + '/20111010203337_create_posts.rb')
          end
          it 'should use destination to find relative root file' do
            expect(group.migration_file('db/migrate/create_posts.rb')).to eq "#{path_to_gem_root_tmp}/db/migrate/20111010203337_create_posts.rb"
          end
          it 'should stick "TIMESTAMP" in when migration does not exist' do
            expect(group.migration_file('db/migrate/migration_that_is_not_there.rb')).to eq "#{path_to_gem_root_tmp}/db/migrate/TIMESTAMP_migration_that_is_not_there.rb"
          end
        end
      end
    end
  end
end