cucumber-rails 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +3 -2
  2. data/HACKING.rdoc +34 -0
  3. data/History.txt +29 -0
  4. data/README.rdoc +48 -22
  5. data/Rakefile +6 -1
  6. data/VERSION +1 -1
  7. data/config/.gitignore +1 -0
  8. data/cucumber-rails.gemspec +49 -25
  9. data/dev_tasks/cucumber.rake +5 -0
  10. data/{tasks → dev_tasks}/rspec.rake +0 -0
  11. data/features/rails2.feature +56 -0
  12. data/features/rails3.feature +52 -0
  13. data/features/step_definitions/cucumber_rails_steps.rb +7 -0
  14. data/features/support/env.rb +4 -0
  15. data/features/support/matchers/files.rb +17 -0
  16. data/generators/cucumber/cucumber_generator.rb +27 -134
  17. data/generators/cucumber/templates/step_definitions/web_steps_ja.rb.erb +136 -0
  18. data/generators/feature/feature_generator.rb +30 -24
  19. data/lib/cucumber/rails/capybara_javascript_emulation.rb +25 -14
  20. data/lib/cucumber/rails/rspec.rb +20 -7
  21. data/lib/cucumber/rails/world.rb +5 -1
  22. data/lib/cucumber/web/tableish.rb +67 -65
  23. data/lib/generators/cucumber/feature/USAGE +16 -0
  24. data/lib/generators/cucumber/feature/feature_base.rb +29 -0
  25. data/lib/generators/cucumber/feature/feature_generator.rb +37 -0
  26. data/lib/generators/cucumber/feature/named_arg.rb +17 -0
  27. data/lib/generators/cucumber/skeleton/USAGE +21 -0
  28. data/lib/generators/cucumber/skeleton/skeleton_base.rb +202 -0
  29. data/lib/generators/cucumber/skeleton/skeleton_generator.rb +64 -0
  30. data/rvm.yml +22 -0
  31. data/spec/cucumber/web/tableish_spec.rb +2 -0
  32. data/spec/generators/cucumber/skeleton/skeleton_base_spec.rb +84 -0
  33. data/spec/spec.opts +2 -0
  34. data/{generators/feature/templates → templates/feature}/feature.erb +18 -12
  35. data/{generators/feature/templates → templates/feature}/steps.erb +0 -0
  36. data/{generators/cucumber/templates → templates/skeleton}/config/cucumber.yml.erb +0 -0
  37. data/{generators/cucumber/templates → templates/skeleton}/environments/cucumber.rb.erb +2 -2
  38. data/{generators/cucumber/templates → templates/skeleton}/script/cucumber +0 -0
  39. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/capybara_steps.rb.erb +18 -8
  40. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_cs.rb.erb +0 -0
  41. data/templates/skeleton/step_definitions/web_steps_da.rb.erb +114 -0
  42. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_de.rb.erb +0 -0
  43. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_es.rb.erb +0 -0
  44. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_no.rb.erb +0 -0
  45. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_pt-BR.rb.erb +0 -0
  46. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/webrat_steps.rb.erb +13 -3
  47. data/{generators/cucumber/templates → templates/skeleton}/support/_rails_each_run.rb +7 -2
  48. data/{generators/cucumber/templates → templates/skeleton}/support/_rails_prefork.rb.erb +1 -1
  49. data/{generators/cucumber/templates → templates/skeleton}/support/capybara.rb +0 -0
  50. data/{generators/cucumber/templates → templates/skeleton}/support/edit_warning.txt +0 -0
  51. data/{generators/cucumber/templates → templates/skeleton}/support/paths.rb +0 -0
  52. data/{generators/cucumber/templates → templates/skeleton}/support/rails.rb.erb +0 -0
  53. data/{generators/cucumber/templates → templates/skeleton}/support/rails_spork.rb.erb +0 -0
  54. data/{generators/cucumber/templates → templates/skeleton}/support/webrat.rb +0 -0
  55. data/{generators/cucumber/templates → templates/skeleton}/tasks/cucumber.rake.erb +1 -1
  56. metadata +77 -31
@@ -3,20 +3,21 @@ module Cucumber
3
3
  module CapybaraJavascriptEmulation
4
4
  def self.included(base)
5
5
  base.class_eval do
6
- alias_method :click_without_rails_javascript_emulation, :click
6
+ alias_method :click_without_javascript_emulation, :click
7
+ alias_method :click, :click_with_javascript_emulation
7
8
  end
8
9
  end
9
10
 
10
- def click_with_rails_javascript_emulation
11
- if link_with_onclick_from_rails?
11
+ def click_with_javascript_emulation
12
+ if link_with_non_get_http_method?
12
13
  Capybara::Driver::RackTest::Form.new(driver, js_form(self[:href], emulated_method)).submit(self)
13
14
  else
14
- click_without_rails_javascript_emulation
15
+ click_without_javascript_emulation
15
16
  end
16
17
  end
17
-
18
18
 
19
19
  private
20
+
20
21
  def js_form(action, emulated_method, method = 'POST')
21
22
  js_form = node.document.create_element('form')
22
23
  js_form['action'] = action
@@ -33,12 +34,20 @@ module Cucumber
33
34
  js_form
34
35
  end
35
36
 
36
- def link_with_onclick_from_rails?
37
- tag_name == 'a' and node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
37
+ def link_with_non_get_http_method?
38
+ if ::Rails.version.to_f >= 3.0
39
+ tag_name == 'a' && node['data-method'] && node['data-method'] =~ /(?:delete|put|post)/
40
+ else
41
+ tag_name == 'a' && node['onclick'] && node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
42
+ end
38
43
  end
39
44
 
40
45
  def emulated_method
41
- node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
46
+ if ::Rails.version.to_f >= 3.0
47
+ node['data-method']
48
+ else
49
+ node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
50
+ end
42
51
  end
43
52
  end
44
53
  end
@@ -47,15 +56,17 @@ end
47
56
  class Capybara::Driver::RackTest::Node
48
57
  include Cucumber::Rails::CapybaraJavascriptEmulation
49
58
  end
50
-
51
- Before('@emulate_rails_javascript') do
59
+
60
+ Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
61
+ # Enable javascript emulation
52
62
  Capybara::Driver::RackTest::Node.class_eval do
53
- alias_method :click, :click_with_rails_javascript_emulation
63
+ alias_method :click, :click_with_javascript_emulation
54
64
  end
55
65
  end
56
-
57
- After('@emulate_rails_javascript') do
66
+
67
+ Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
68
+ # Disable javascript emulation
58
69
  Capybara::Driver::RackTest::Node.class_eval do
59
- alias_method :click, :click_without_rails_javascript_emulation
70
+ alias_method :click, :click_without_javascript_emulation
60
71
  end
61
72
  end
@@ -1,10 +1,23 @@
1
1
  require 'cucumber/rails/world'
2
- require 'spec/expectations'
3
- require 'spec/rails'
4
2
 
5
- [Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
6
- klass.class_eval do
7
- include Spec::Matchers
8
- include Spec::Rails::Matchers
3
+ begin
4
+ require 'rspec/expectations'
5
+ require 'rspec/rails'
6
+
7
+ [Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
8
+ klass.class_eval do
9
+ include Rspec::Matchers
10
+ include Rspec::Rails::Matchers
11
+ end
12
+ end
13
+ rescue LoadError => try_rspec_1
14
+ require 'spec/expectations'
15
+ require 'spec/rails'
16
+
17
+ [Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
18
+ klass.class_eval do
19
+ include Spec::Matchers
20
+ include Spec::Rails::Matchers
21
+ end
9
22
  end
10
- end
23
+ end
@@ -6,7 +6,11 @@ unless defined?(Test)
6
6
  end
7
7
 
8
8
  if defined?(ActiveRecord::Base)
9
- require 'test_help'
9
+ if Rails.version.to_f >= 3.0
10
+ require 'rails/test_help'
11
+ else
12
+ require 'test_help'
13
+ end
10
14
  else
11
15
  # I can't do rescue LoadError because in this files could be loaded
12
16
  # from rails gem (ie. load actionpack 2.3.5 if rubygems are not disabled)
@@ -1,75 +1,77 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module Cucumber
4
- module Tableish
5
- # This method returns an Array of Array of String, using CSS3 selectors.
6
- # This is particularly handy when using Cucumber's Table#diff! method.
7
- #
8
- # The +row_selector+ argument must be a String, and picks out all the rows
9
- # from the web page's DOM. If the number of cells in each row differs, it
10
- # will be constrained by (or padded with) the number of cells in the first row
11
- #
12
- # The +column_selectors+ argument must be a String or a Proc, picking out
13
- # cells from each row. If you pass a Proc, it will be yielded an instance
14
- # of Nokogiri::HTML::Element.
15
- #
16
- # == Example with a table
17
- #
18
- # <table id="tools">
19
- # <tr>
20
- # <th>tool</th>
21
- # <th>dude</th>
22
- # </tr>
23
- # <tr>
24
- # <td>webrat</td>
25
- # <td>bryan</td>
26
- # </tr>
27
- # <tr>
28
- # <td>cucumber</td>
29
- # <td>aslak</td>
30
- # </tr>
31
- # </table>
32
- #
33
- # t = tableish('table#tools tr', 'td,th')
34
- #
35
- # == Example with a dl
36
- #
37
- # <dl id="tools">
38
- # <dt>webrat</dt>
39
- # <dd>bryan</dd>
40
- # <dt>cucumber</dt>
41
- # <dd>aslak</dd>
42
- # </dl>
43
- #
44
- # t = tableish('dl#tools dt', lambda{|dt| [dt, dt.next.next]})
45
- #
46
- def tableish(row_selector, column_selectors)
47
- html = defined?(Capybara) ? body : response_body
48
- _tableish(html, row_selector, column_selectors)
49
- end
4
+ module Web
5
+ module Tableish
6
+ # This method returns an Array of Array of String, using CSS3 selectors.
7
+ # This is particularly handy when using Cucumber's Table#diff! method.
8
+ #
9
+ # The +row_selector+ argument must be a String, and picks out all the rows
10
+ # from the web page's DOM. If the number of cells in each row differs, it
11
+ # will be constrained by (or padded with) the number of cells in the first row
12
+ #
13
+ # The +column_selectors+ argument must be a String or a Proc, picking out
14
+ # cells from each row. If you pass a Proc, it will be yielded an instance
15
+ # of Nokogiri::HTML::Element.
16
+ #
17
+ # == Example with a table
18
+ #
19
+ # <table id="tools">
20
+ # <tr>
21
+ # <th>tool</th>
22
+ # <th>dude</th>
23
+ # </tr>
24
+ # <tr>
25
+ # <td>webrat</td>
26
+ # <td>bryan</td>
27
+ # </tr>
28
+ # <tr>
29
+ # <td>cucumber</td>
30
+ # <td>aslak</td>
31
+ # </tr>
32
+ # </table>
33
+ #
34
+ # t = tableish('table#tools tr', 'td,th')
35
+ #
36
+ # == Example with a dl
37
+ #
38
+ # <dl id="tools">
39
+ # <dt>webrat</dt>
40
+ # <dd>bryan</dd>
41
+ # <dt>cucumber</dt>
42
+ # <dd>aslak</dd>
43
+ # </dl>
44
+ #
45
+ # t = tableish('dl#tools dt', lambda{|dt| [dt, dt.next.next]})
46
+ #
47
+ def tableish(row_selector, column_selectors)
48
+ html = defined?(Capybara) ? body : response_body
49
+ _tableish(html, row_selector, column_selectors)
50
+ end
50
51
 
51
- def _tableish(html, row_selector, column_selectors) #:nodoc
52
- doc = Nokogiri::HTML(html)
53
- column_count = nil
54
- doc.search(row_selector).map do |row|
55
- cells = case(column_selectors)
56
- when String
57
- row.search(column_selectors)
58
- when Proc
59
- column_selectors.call(row)
60
- end
61
- column_count ||= cells.length
62
- (0...column_count).map do |n|
63
- cell = cells[n]
64
- case(cell)
65
- when String then cell.strip
66
- when nil then ''
67
- else cell.text.strip
52
+ def _tableish(html, row_selector, column_selectors) #:nodoc
53
+ doc = Nokogiri::HTML(html)
54
+ column_count = nil
55
+ doc.search(row_selector).map do |row|
56
+ cells = case(column_selectors)
57
+ when String
58
+ row.search(column_selectors)
59
+ when Proc
60
+ column_selectors.call(row)
61
+ end
62
+ column_count ||= cells.length
63
+ (0...column_count).map do |n|
64
+ cell = cells[n]
65
+ case(cell)
66
+ when String then cell.strip
67
+ when nil then ''
68
+ else cell.text.strip
69
+ end
68
70
  end
69
71
  end
70
72
  end
71
- end
73
+ end
72
74
  end
73
75
  end
74
76
 
75
- World(Cucumber::Tableish)
77
+ World(Cucumber::Web::Tableish)
@@ -0,0 +1,16 @@
1
+ Description:
2
+ Generates a skeleton for a new feature. Both a simple .feature file and
3
+ a steps.rb file is generated. This generator should be used with moderation.
4
+ See http://github.com/aslakhellesoy/cucumber/wikis/feature-coupled-steps-antipattern
5
+ for details about the dangers involved.
6
+
7
+ This generator can take an optional list of attribute pairs similar to Rails'
8
+ built-in resource generator.
9
+
10
+ Examples (Rails 3):
11
+ `script/rails generate cucumber:feature post` # no attributes
12
+ `script/rails generate cucumber:feature post title:string body:text published:boolean`
13
+
14
+ Examples (Rails 2):
15
+ `script/generate feature post` # no attributes
16
+ `script/generate feature post title:string body:text published:boolean`
@@ -0,0 +1,29 @@
1
+ module Cucumber
2
+ module Generators
3
+ module FeatureBase
4
+
5
+ def create_directory(m = self, rails2 = false)
6
+ if rails2
7
+ m.directory 'features/step_definitions'
8
+ else
9
+ m.empty_directory 'features/step_definitions'
10
+ end
11
+ end
12
+
13
+ def create_feature_file(m = self)
14
+ m.template 'feature.erb', "features/manage_#{plural_name}.feature"
15
+ end
16
+
17
+ def create_steps_file(m = self)
18
+ m.template 'steps.erb', "features/step_definitions/#{singular_name}_steps.rb"
19
+ end
20
+
21
+ def create_support_file(m = self)
22
+ m.gsub_file 'features/support/paths.rb', /'\/'/mi do |match|
23
+ "#{match}\n when /the new #{singular_name} page/\n new_#{singular_name}_path\n"
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'named_arg')
2
+ require File.join(File.dirname(__FILE__), 'feature_base')
3
+
4
+ module Cucumber
5
+ class FeatureGenerator < Rails::Generators::NamedBase
6
+
7
+ include Cucumber::Generators::FeatureBase
8
+
9
+ argument :fields, :optional => true, :type => :array, :banner => "[field:type, field:type]"
10
+
11
+ attr_reader :named_args
12
+
13
+ def parse_fields
14
+ @named_args = @fields.nil? ? [] : @fields.map { |arg| NamedArg.new(arg) }
15
+ end
16
+
17
+ def generate
18
+ create_directory
19
+ create_feature_file
20
+ create_steps_file
21
+ create_support_file
22
+ end
23
+
24
+ def self.banner
25
+ "#{$0} cucumber:feature ModelName [field:type, field:type]"
26
+ end
27
+
28
+ def self.gem_root
29
+ File.expand_path("../../../../../", __FILE__)
30
+ end
31
+
32
+ def self.source_root
33
+ File.join(gem_root, 'templates', 'feature')
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ class NamedArg
2
+ attr_reader :name
3
+ attr_reader :type
4
+
5
+ def initialize(s)
6
+ @name, @type = *s.split(':')
7
+ end
8
+
9
+ def value(n)
10
+ if @type == 'boolean'
11
+ (n % 2) == 0
12
+ else
13
+ "#{@name} #{n}"
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,21 @@
1
+ Description:
2
+ Sets up Cucumber in your Rails project. After running this generator you will
3
+ get a new rake task called features.
4
+
5
+ This also generates the necessary files in the features directory.
6
+
7
+ Also see the feature generator, which you can use to generate skeletons
8
+ for new features.
9
+
10
+ Examples (Rails 3):
11
+ `script/rails generate cucumber:skeleton`
12
+
13
+ You can also provide a language argument for localized webrat_steps:
14
+ `script/rails generate cucumber:skeleton de`
15
+
16
+ Examples (Rails 2):
17
+ `script/generate cucumber`
18
+
19
+ You can also provide a language argument for localized webrat_steps:
20
+ `script/generate cucumber de`
21
+
@@ -0,0 +1,202 @@
1
+ module Cucumber
2
+ module Generators
3
+ module SkeletonBase
4
+
5
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
6
+
7
+ # Checks and prints the limitations
8
+ def check_upgrade_limitations
9
+ if File.exist?('features/step_definitions/webrat_steps.rb')
10
+ STDERR.puts "Please remove features/step_definitions/webrat_steps.rb\n" +
11
+ "See upgrading instructions for 0.2.0 in History.txt"
12
+ exit(1)
13
+ end
14
+
15
+ if File.exist?('features/support/version_check.rb')
16
+ STDERR.puts "Please remove features/support/version_check.rb\n" +
17
+ "See upgrading instructions for 0.2.0 in History.txt"
18
+ exit(1)
19
+ end
20
+ end
21
+
22
+ # Creates templates
23
+ def create_templates(m = self, rails2 = false)
24
+ m.template 'config/cucumber.yml.erb', 'config/cucumber.yml'
25
+ if rails2
26
+ m.template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
27
+ end
28
+ end
29
+
30
+ def configure_gemfile(m = self, rails2 = false)
31
+ require 'thor-ext'
32
+ unless rails2
33
+ puts "Update Rails 3 Gemfile for cucumber"
34
+ gsub_file 'Gemfile', /('|")gem/, "\1\ngem"
35
+ add_gem('database_cleaner', '>=0.5.0') unless has_plugin? 'database_cleaner'
36
+ if driver == :capybara
37
+ add_gem('capybara', '>=0.3.0')
38
+ else
39
+ add_gem('webrat', '>=0.7.0') unless has_plugin? 'webrat'
40
+ end
41
+ if framework == :rspec
42
+ add_gem('rspec', '>=1.3.0') unless has_plugin? 'rspec'
43
+ add_gem('rspec-rails', '>=1.3.2') unless has_plugin? 'rspec-rails'
44
+ end
45
+ if spork?
46
+ add_gem('spork''>=0.7.5') unless has_plugin? 'spork'
47
+ end
48
+ add_gems(%w{cucumber cucumber-rails})
49
+ end
50
+ end
51
+
52
+ def create_scripts(m = self, rails2 = false)
53
+ if rails2
54
+ m.file 'script/cucumber', 'script/cucumber', {
55
+ :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
56
+ }
57
+ else
58
+ m.copy_file 'script/cucumber', 'script/cucumber'
59
+ m.chmod 'script/cucumber', 0755
60
+ end
61
+ end
62
+
63
+ def create_step_definitions(m = self, rails2 = false)
64
+ if rails2
65
+ m.directory 'features/step_definitions'
66
+ else
67
+ m.empty_directory 'features/step_definitions'
68
+ end
69
+
70
+ m.template "step_definitions/#{driver}_steps.rb.erb", 'features/step_definitions/web_steps.rb'
71
+ if language != 'en'
72
+ m.template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps_#{language}.rb"
73
+ end
74
+ end
75
+
76
+ def create_feature_support(m = self, rails2 = false)
77
+ if rails2
78
+ m.directory 'features/support'
79
+ m.file 'support/paths.rb', 'features/support/paths.rb'
80
+
81
+ if spork?
82
+ m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
83
+ else
84
+ m.template 'support/rails.rb.erb', 'features/support/env.rb'
85
+ end
86
+ else
87
+ m.empty_directory 'features/support'
88
+ m.copy_file 'support/paths.rb', 'features/support/paths.rb'
89
+
90
+ if spork?
91
+ m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
92
+ else
93
+ m.template 'support/rails.rb.erb', 'features/support/env.rb'
94
+ end
95
+ end
96
+ end
97
+
98
+ def create_tasks(m = self, rails2 = false)
99
+ if rails2
100
+ m.directory 'lib/tasks'
101
+ else
102
+ m.empty_directory 'lib/tasks'
103
+ end
104
+
105
+ m.template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
106
+ end
107
+
108
+ def create_database(m = self, rails2 = false)
109
+ unless File.read('config/database.yml').include? 'cucumber:'
110
+ m.gsub_file 'config/database.yml', /^test:.*\n/, "test: &TEST\n"
111
+ m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
112
+
113
+ # Since gsub_file doesn't ask the user, just inform user that the file was overwritten.
114
+ puts " force config/database.yml"
115
+ end
116
+ end
117
+
118
+ def print_instructions
119
+ require 'cucumber/formatter/ansicolor'
120
+ extend Cucumber::Formatter::ANSIColor
121
+
122
+ if @default_driver
123
+ puts <<-WARNING
124
+
125
+ #{yellow_cukes(15)}
126
+
127
+ #{yellow_cukes(1)} D R I V E R A L E R T #{yellow_cukes(1)}
128
+
129
+ You didn't explicitly generate with --capybara or --webrat, so I looked at
130
+ your gems and saw that you had #{green(@default_driver.to_s)} installed, so I went with that.
131
+ If you want something else, be specific about it. Otherwise, relax.
132
+
133
+ #{yellow_cukes(15)}
134
+
135
+ WARNING
136
+ end
137
+ end
138
+
139
+ protected
140
+
141
+ def detect_current_driver
142
+ detect_in_env([['capybara', :capybara], ['webrat', :webrat]])
143
+ end
144
+
145
+ def detect_default_driver
146
+ @default_driver = first_loadable([['capybara', :capybara], ['webrat', :webrat]])
147
+ raise "I don't know which driver you want. Use --capybara or --webrat, or gem install capybara or webrat." unless @default_driver
148
+ @default_driver
149
+ end
150
+
151
+ def detect_current_framework
152
+ detect_in_env([['spec', :rspec]]) || :testunit
153
+ end
154
+
155
+ def detect_default_framework
156
+ # TODO need to check this - defaulting to :testunit has been moved from first_loadable
157
+ # It's unlikely that we don't have test/unit since it comes with Ruby
158
+ @default_framework ||= first_loadable([['rspec', :rspec]])
159
+ end
160
+
161
+ def spork?
162
+ options[:spork]
163
+ end
164
+
165
+ def embed_file(source, indent='')
166
+ IO.read(File.join(self.class.source_root, source)).gsub(/^/, indent)
167
+ end
168
+
169
+ def embed_template(source, indent='')
170
+ template = File.join(self.class.source_root, source)
171
+ ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
172
+ end
173
+
174
+ def version
175
+ IO.read(File.join(self.class.gem_root, 'VERSION')).chomp
176
+ end
177
+
178
+ def first_loadable(libraries)
179
+ require 'rubygems'
180
+
181
+ libraries.each do |lib_name, lib_key|
182
+ return lib_key if Gem.available?(lib_name)
183
+ end
184
+
185
+ nil
186
+ end
187
+
188
+ def detect_in_env(choices)
189
+ return nil unless File.file?("features/support/env.rb")
190
+
191
+ env = IO.read("features/support/env.rb")
192
+
193
+ choices.each do |choice|
194
+ detected = choice[1] if env =~ /#{choice[0]}/n
195
+ return detected if detected
196
+ end
197
+
198
+ nil
199
+ end
200
+ end
201
+ end
202
+ end