ixtlan-generators 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1,160 @@
1
- require 'maven/cucumber_steps'
1
+ require 'fileutils'
2
+ require 'ruby-maven'
3
+ module Maven
4
+ class CucumberSteps
5
+
6
+ def initialize(options = {})
7
+ @options = {:ruby_version => RUBY_VERSION }
8
+ @options[:jruby_version] = JRUBY_VERSION if defined? JRUBY_VERSION
9
+
10
+ @options.merge!(options || {})
11
+ end
12
+
13
+ def rmvn
14
+ @rmvn ||= Maven::RubyMaven.new
15
+ end
16
+
17
+ def copy_tests(tests)
18
+ FileUtils.mkdir_p(@app_directory)
19
+ FileUtils.cp_r(File.join('templates', "tests-#{tests}", "."),
20
+ File.join(@app_directory, 'test'),
21
+ :remove_destination => true)
22
+ end
23
+
24
+ def copy_specs(specs)
25
+ FileUtils.mkdir_p(@app_directory)
26
+ FileUtils.cp_r(File.join('templates', "specs-#{specs}", "."),
27
+ File.join(@app_directory, 'spec'),
28
+ :remove_destination => true)
29
+ end
30
+
31
+ def copy_files(files)
32
+ FileUtils.mkdir_p(@app_directory)
33
+ FileUtils.cp_r(File.join('templates', "files-#{files}", "."),
34
+ @app_directory,
35
+ :remove_destination => true)
36
+ end
37
+
38
+ def create_rails_application(template)
39
+ name = template.sub(/.template$/, '')
40
+ @app_directory = File.join('target', name)
41
+
42
+ # rails version from gemspec
43
+ gemspec = File.read(Dir.glob("*.gemspec")[0])
44
+ rails_version = gemspec.split("\n").detect { |l| l =~ /development_dep.*rails/ }.sub(/'$/, '').sub(/.*'/, '')
45
+
46
+ rmvn.options['-Dplugin.version'] = @options[:plugin_version] if @options[:plugin_version]
47
+ rmvn.options['-Djruby.version'] = @options[:jruby_version] if @options[:jruby_version]
48
+ if @options[:ruby_version]
49
+ rversion = @options[:ruby_version] =~ /^1.8./ ? '--1.8': '--1.9'
50
+ rmvn.options['-Djruby.switches'] = rversion
51
+ end
52
+
53
+ rmvn.options['-Drails.version'] = rails_version
54
+ rmvn.options['-Dgem.home'] = ENV['GEM_HOME']
55
+ rmvn.options['-Dgem.path'] = ENV['GEM_PATH']
56
+ rmvn.options['-o'] = nil
57
+
58
+ FileUtils.rm_rf(@app_directory)
59
+
60
+ template_file = File.expand_path("templates/#{template}")
61
+ rmvn.exec("rails", "new", @app_directory, "-f", '--', '-e', "-Dtemplate=#{template_file}")
62
+ end
63
+
64
+ def given_template(template)
65
+ create_rails_application(template)
66
+ end
67
+
68
+ def given_template_and_tests(template, tests)
69
+ create_rails_application(template)
70
+ copy_tests(tests)
71
+ end
72
+
73
+ def given_template_and_specs(template, specs)
74
+ create_rails_application(template)
75
+ copy_specs(specs)
76
+ end
77
+
78
+ def given_template_and_files(template, files)
79
+ create_rails_application(template)
80
+ copy_files(files)
81
+ end
82
+
83
+ def given_application(name)
84
+ @app_directory = File.join('target', name)
85
+ end
86
+
87
+ def given_application_and_tests(name, tests)
88
+ @app_directory = File.join('target', name)
89
+ copy_tests(tests)
90
+ end
91
+
92
+ def given_application_and_specs(name, specs)
93
+ @app_directory = File.join('target', name)
94
+ copy_specs(specs)
95
+ end
96
+
97
+ def given_application_and_files(name, files)
98
+ @app_directory = File.join('target', name)
99
+ copy_files(files)
100
+ end
101
+
102
+ def execute(args)
103
+ rmvn.options['-l'] = "output.log"
104
+ rmvn.exec_in(@app_directory, args.split(' '))
105
+ end
106
+
107
+ def expected_output(expected)
108
+ result = File.read(File.join(@app_directory, "output.log"))
109
+ expected.split(/\"?\s+and\s+\"?/).each do |exp|
110
+ puts exp
111
+ yield(result =~ /.*#{exp}.*/)
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+ steps = Maven::CucumberSteps.new(:plugin_version => '0.29.0')
119
+
120
+ Given /^I create new rails application with template "(.*)"$/ do |template|
121
+ steps.given_template(template)
122
+ end
123
+
124
+ Given /^I create new rails application with template "(.*)" and "(.*)" tests$/ do |template, tests|
125
+ steps.given_template_and_tests(template, tests)
126
+ end
127
+
128
+ Given /^I create new rails application with template "(.*)" and "(.*)" specs$/ do |template, specs|
129
+ steps.given_template_and_specs(template, specs)
130
+ end
131
+
132
+ Given /^I create new rails application with template "(.*)" and "(.*)" files$/ do |template, files|
133
+ steps.given_template_and_files(template, files)
134
+ end
135
+
136
+ Given /^me an existing rails application "(.*)"$/ do |name|
137
+ steps.given_application(name)
138
+ end
139
+
140
+ Given /^me an existing rails application "(.*)" and "(.*)" tests$/ do |name, tests|
141
+ steps.given_application_and_tests(name, tests)
142
+ end
143
+
144
+ Given /^me an existing rails application "(.*)" and "(.*)" specs$/ do |name, specs|
145
+ steps.given_application_and_specs(name, specs)
146
+ end
147
+
148
+ Given /^me an existing rails application "(.*)" and "(.*)" files$/ do |name, files|
149
+ steps.given_application_and_files(name, files)
150
+ end
151
+
152
+ And /^I execute \"(.*)\"$/ do |args|
153
+ steps.execute(args)
154
+ end
155
+
156
+ Then /^the output should contain \"(.*)\"$/ do |expected|
157
+ steps.expected_output(expected) do |exp|
158
+ exp.should_not be_nil
159
+ end
160
+ end
@@ -25,7 +25,8 @@ module Ixtlan
25
25
  end
26
26
 
27
27
  class Railtie < Rails::Railtie
28
- config.generators do |config|
28
+ gmethod = config.respond_to?(:generators) ? :generators : :app_generators
29
+ config.send(gmethod) do |config|
29
30
 
30
31
  config.templates << File.expand_path('../../generators/rails', __FILE__)
31
32
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ixtlan-generators
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - mkristian
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-30 00:00:00 +05:30
14
- default_executable:
13
+ date: 2012-07-03 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: ixtlan-core
@@ -171,7 +170,6 @@ files:
171
170
  - features/audit.feature
172
171
  - features/generators.feature
173
172
  - features/error-handler.feature
174
- has_rdoc: true
175
173
  homepage: http://github.com/mkristian/ixtlan-generators
176
174
  licenses:
177
175
  - MIT-LICENSE
@@ -195,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
193
  requirements: []
196
194
 
197
195
  rubyforge_project:
198
- rubygems_version: 1.5.1
196
+ rubygems_version: 1.8.24
199
197
  signing_key:
200
198
  specification_version: 3
201
199
  summary: rails generator templates for ixtlan gems