File: project_initializer_spec.rb

package info (click to toggle)
ruby-rspec-core 2.14.7-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,756 kB
  • ctags: 1,195
  • sloc: ruby: 12,708; makefile: 14
file content (130 lines) | stat: -rw-r--r-- 4,216 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require "spec_helper"

module RSpec::Core
  describe ProjectInitializer, :isolated_directory => true do

    describe "#run" do
      context "with no args" do
        let(:command_line_config) { ProjectInitializer.new }

        before do
          command_line_config.stub(:warn)
          command_line_config.stub(:puts)
          command_line_config.stub(:gets => 'no')
        end

        context "with no .rspec file" do
          it "says it's creating .rspec " do
            command_line_config.should_receive(:puts).with(/create\s+\.rspec/)
            command_line_config.run
          end

          it "generates a .rspec" do
            command_line_config.run
            expect(File.read('.rspec')).to match(/--color\n--format progress/m)
          end
        end

        context "with a .rspec file" do
          it "says .rspec exists" do
            FileUtils.touch('.rspec')
            command_line_config.should_receive(:puts).with(/exist\s+\.rspec/)
            command_line_config.run
          end

          it "doesn't create a new one" do
            File.open('.rspec', 'w') {|f| f << '--color'}
            command_line_config.run
            expect(File.read('.rspec')).to eq('--color')
          end
        end

        context "with no spec/spec_helper.rb file" do
          it "says it's creating spec/spec_helper.rb " do
            command_line_config.should_receive(:puts).with(/create\s+spec\/spec_helper.rb/)
            command_line_config.run
          end

          it "generates a spec/spec_helper.rb" do
            command_line_config.run
            expect(File.read('spec/spec_helper.rb')).to match(/RSpec\.configure do \|config\|/m)
          end
        end

        context "with a spec/spec_helper.rb file" do
          before { FileUtils.mkdir('spec') }

          it "says spec/spec_helper.rb exists" do
            FileUtils.touch('spec/spec_helper.rb')
            command_line_config.should_receive(:puts).with(/exist\s+spec\/spec_helper.rb/)
            command_line_config.run
          end

          it "doesn't create a new one" do
            random_content = "content #{rand}"
            File.open('spec/spec_helper.rb', 'w') {|f| f << random_content}
            command_line_config.run
            expect(File.read('spec/spec_helper.rb')).to eq(random_content)
          end
        end

        context "with autotest/discover.rb" do
          before do
            FileUtils.mkdir('autotest')
            FileUtils.touch 'autotest/discover.rb'
          end

          it "asks whether to delete the file" do
            command_line_config.should_receive(:puts).with(/delete/)
            command_line_config.run
          end

          it "removes it if confirmed" do
            command_line_config.stub(:gets => 'yes')
            command_line_config.run
            expect(File.exist?('autotest/discover.rb')).to be_false
          end

          it "leaves it if not confirmed" do
            command_line_config.stub(:gets => 'no')
            command_line_config.run
            expect(File.exist?('autotest/discover.rb')).to be_true
          end
        end

        context "with lib/tasks/rspec.rake" do
          before do
            FileUtils.mkdir_p('lib/tasks')
            FileUtils.touch 'lib/tasks/rspec.rake'
          end

          it "asks whether to delete the file" do
            command_line_config.should_receive(:puts).with(/delete/)
            command_line_config.run
          end

          it "removes it if confirmed" do
            command_line_config.stub(:gets => 'yes')
            command_line_config.run
            expect(File.exist?('lib/tasks/rspec.rake')).to be_false
          end

          it "leaves it if not confirmed" do
            command_line_config.stub(:gets => 'no')
            command_line_config.run
            expect(File.exist?('lib/tasks/rspec.rake')).to be_true
          end
        end
      end

      context "given an arg" do
        it "warns if arg received (no longer necessary)" do
          config = ProjectInitializer.new("another_arg")
          config.stub(:puts)
          config.stub(:gets => 'no')
          config.run
        end
      end
    end
  end
end