File: test_case_spec.rb

package info (click to toggle)
ruby-generator-spec 0.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: ruby: 538; makefile: 5
file content (70 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

class TestClass
  
end

describe GeneratorSpec::TestCase do
  before do
    @klass = Class.new do
      def self.described_class
        TestClass
      end
      include GeneratorSpec::TestCase
    end
    @klass.test_case_instance = double
  end
  
  it 'passes unknown messages on to test_case_instance' do
    expect(@klass.test_case_instance).to receive(:assert_file).with('test')
    @klass.new.assert_file('test')
  end
  
  it 'handles respond_to accordingly' do
    expect(@klass.test_case_instance).to receive(:respond_to?).with(:assert_no_file).and_return(true)
    expect(@klass.new.respond_to?(:assert_no_file)).to be_truthy
  end
end

describe TestGenerator, 'using normal assert methods', :type => 'generator' do
  destination File.expand_path('../../tmp', __FILE__)
  arguments %w(test --test)
  
  before(:all) do
    prepare_destination
    run_generator
  end

  it 'creates a test initializer' do
    assert_file 'config/initializers/test.rb', '# Initializer'
  end

  it 'creates a migration' do
    assert_migration 'db/migrate/create_tests.rb'
  end

  it 'removes files' do
    assert_no_file '.gitignore'
  end
end

describe TestGenerator, 'with contexts', :type => 'generator' do
  destination File.expand_path('../../tmp', __FILE__)
  before { prepare_destination }
  
  context 'with --test flag' do
    before { run_generator %w(test --test) }
    
    it 'creates a test initializer' do
      assert_file 'config/initializers/test.rb', '# Initializer'
    end
  end
  
  context 'without any flags' do
    before { run_generator %w(test) }
    
    it 'doesn\'t create a test initializer' do
      assert_no_file 'config/initializers/test.rb'
    end
  end
end