Module: Cucumber::Generators::InstallBase

Included in:
InstallGenerator
Defined in:
lib/generators/cucumber/install/install_base.rb

Constant Summary collapse

DEFAULT_SHEBANG =
File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])

Instance Method Summary collapse

Instance Method Details

#check_upgrade_limitationsObject

Checks and prints the limitations



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/cucumber/install/install_base.rb', line 8

def check_upgrade_limitations
  if File.exist?('features/step_definitions/webrat_steps.rb')
    STDERR.puts "Please remove features/step_definitions/webrat_steps.rb\n" +
    "See upgrading instructions for 0.2.0 in History.txt"
    exit(1)
  end

  if File.exist?('features/support/version_check.rb')
    STDERR.puts "Please remove features/support/version_check.rb\n" +
    "See upgrading instructions for 0.2.0 in History.txt"
    exit(1)
  end
end

#configure_gemfile(m = self, rails2 = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/cucumber/install/install_base.rb', line 30

def configure_gemfile(m = self, rails2 = false)
  require 'thor-ext'
  unless rails2
    puts "Update Rails 3 Gemfile for cucumber"
    gsub_file 'Gemfile', /('|")gem/, "\1\ngem"
    add_gem('database_cleaner', '>=0.5.2') unless has_plugin? 'database_cleaner'
    if driver == :capybara
      add_gem('capybara', '>=0.3.7')
    else
      add_gem('webrat', '>=0.7.0') unless has_plugin? 'webrat'
    end
    if framework == :rspec
      add_gem('rspec', '>=1.3.0') unless has_plugin? 'rspec'
      add_gem('rspec-rails', '>=1.3.2') unless has_plugin? 'rspec-rails'
    end
    if spork?
      add_gem('spork''>=0.7.5') unless has_plugin? 'spork'
    end
    add_gems(%w{cucumber cucumber-rails})
  end
end

#create_database(m = self, rails2 = false) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/generators/cucumber/install/install_base.rb', line 108

def create_database(m = self, rails2 = false)
  unless File.read('config/database.yml').include? 'cucumber:'
    m.gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
    m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n  <<: *test"
    
    # Since gsub_file doesn't ask the user, just inform user that the file was overwritten.
    puts "       force  config/database.yml"
  end
end

#create_feature_support(m = self, rails2 = false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/generators/cucumber/install/install_base.rb', line 76

def create_feature_support(m = self, rails2 = false)
  if rails2
    m.directory 'features/support'
    m.file      'support/paths.rb', 'features/support/paths.rb'

    if spork?
      m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
    else
      m.template 'support/rails.rb.erb',       'features/support/env.rb'
    end
  else
    m.empty_directory 'features/support'
    m.copy_file 'support/paths.rb', 'features/support/paths.rb'

    if spork?
      m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
    else
      m.template 'support/rails.rb.erb',       'features/support/env.rb'
    end
  end
end

#create_scripts(m = self, rails2 = false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/cucumber/install/install_base.rb', line 52

def create_scripts(m = self, rails2 = false)
  if rails2
    m.file 'script/cucumber', 'script/cucumber', {
      :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
    }
  else
    m.copy_file 'script/cucumber', 'script/cucumber'
    m.chmod     'script/cucumber', 0755
  end
end

#create_step_definitions(m = self, rails2 = false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/cucumber/install/install_base.rb', line 63

def create_step_definitions(m = self, rails2 = false)
  if rails2
    m.directory 'features/step_definitions'
  else
    m.empty_directory 'features/step_definitions'
  end

  m.template "step_definitions/#{driver}_steps.rb.erb", 'features/step_definitions/web_steps.rb'
  if language != 'en'
    m.template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps_#{language}.rb"
  end
end

#create_tasks(m = self, rails2 = false) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/generators/cucumber/install/install_base.rb', line 98

def create_tasks(m = self, rails2 = false)
  if rails2
    m.directory 'lib/tasks'
  else
    m.empty_directory 'lib/tasks'
  end

  m.template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
end

#create_templates(m = self, rails2 = false) ⇒ Object

Creates templates



23
24
25
26
27
28
# File 'lib/generators/cucumber/install/install_base.rb', line 23

def create_templates(m = self, rails2 = false)
  m.template 'config/cucumber.yml.erb', 'config/cucumber.yml'
  if rails2
    m.template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
  end
end


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/generators/cucumber/install/install_base.rb', line 118

def print_instructions
  require 'cucumber/formatter/ansicolor'
  extend Cucumber::Formatter::ANSIColor

  if @default_driver
    puts <<-WARNING

    #{yellow_cukes(15)}

            #{yellow_cukes(1)}   D R I V E R   A L E R T    #{yellow_cukes(1)}

    You didn't explicitly generate with --capybara or --webrat, so I looked at
    your gems and saw that you had #{green(@default_driver.to_s)} installed, so I went with that.
    If you want something else, be specific about it. Otherwise, relax.

    #{yellow_cukes(15)}

    WARNING
  end
end