Permalink
Browse files

added cucumber features for testing the generators

  • Loading branch information...
mkristian committed Dec 11, 2010
1 parent ebb7507 commit 7737ebf506d31e183bc456c52a19eb45c94efd04
View
@@ -95,7 +95,7 @@ setup a log4j logging (fallback on rails logging without JRUBY)
$ rails3 generate slf4r:log4j
-but to use this you need to add slf4j-log4j12-1.6.1.jar to you classpath or require the jar
+but to use this you need to add slf4j-log4j12-1.6.1.jar to you classpath or require the jar. see below how to do this with ruby-maven gem.
setup a logging from logging gem
@@ -110,6 +110,25 @@ all these setups use the same files as default rails and adjust the log level fr
* ActionMailer
* ActiveSupport::Cache::Store
+== use ruby-maven to add jar files to your rails3 application (experimental)
+
+install it with
+$ jruby -S gem install ruby-maven --pre
+
+then you can run the rails3 with log4j wioth
+$ rmvn rails server
+or the generator
+$ rmv rails generate . .
+or the rake
+$ rmvn rake . . .
+or console/dbconsole
+$ rmvn rails console
+$ rmvn rails dbconsole
+or run the server in jetty
+$ jetty-run
+
+*NOTE* it is a prerelease so there are bugs and limitations
+
== TODO:
* the bridge from ruby to java, i.e. using rails logging for java libraries using slf4j, i.e. the java classes will log into the rails logging framework
@@ -0,0 +1,13 @@
+Feature: Generators for slf4r
+
+ Scenario: The slf4r rails template creates a rails application which uses slf4r-wrapper
+ Given I create new rails application with template "simple.template"
+ Then the output should contain "setup slf4r logger wrapper with ActiveSupport::BufferedLogger"
+
+ Scenario: The slf4r rails template creates a rails application which uses logging gem
+ Given I create new rails application with template "logging.template"
+ Then the output should contain "INFO \(Rails\) - setup slf4r logger categories for Logging::Logger"
+
+ Scenario: The slf4r rails template creates a rails application which uses log4j
+ Given I create new rails application with template "log4j.template"
+ Then the output should contain "INFO \(Rails\) - setup slf4r logger categories for org.slf4j.impl.Log4jLoggerAdapter"
@@ -0,0 +1,22 @@
+require 'fileutils'
+Given /^I create new rails application with template "(.*)"$/ do |template|
+ name = template.sub(/.template$/, '')
+ directory = File.join('target', name)
+ rails_version = ENV['RAILS_VERSION'] || '3.0.1'
+
+ ruby = defined?(JRUBY_VERSION) ? "jruby" : "ruby"
+ rails_command = "#{ENV['GEM_HOME']}/bin/rails"
+ rails_command = "-S rails" unless File.exists?(rails_command)
+ command = "#{rails_command} _#{rails_version}_ new #{directory} -f -m templates/#{template}"
+ FileUtils.rm_rf(directory)
+
+ system "#{ruby} #{command}"
+
+ @result = File.read("target/#{name}/log/development.log")
+ puts @result
+end
+
+Then /^the output should contain \"(.*)\"$/ do |expected|
+ (@result =~ /.*#{expected}.*/).should_not be_nil
+end
+
@@ -5,5 +5,16 @@ def setup
source = File.expand_path('../../templates', __FILE__)
initializer "log4j.rb", File.read(File.join(source, "log4j.rb"))
initializer "log4j.properties", File.read(File.join(source, "log4j.properties"))
+
+ gemfile = File.read('Gemfile')
+ jar_line = "org.slf4j.slf4j-log4j12"
+ unless gemfile =~ /#{jar_line}/
+ File.open('Gemfile', 'a') do |f|
+ f.puts
+ f.puts "if defined? MAVEN"
+ f.puts " jar '#{jar_line}', '1.6.1'"
+ f.puts "end"
+ end
+ end
end
end
@@ -24,7 +24,7 @@ class Slf4rRailtie < Rails::Railtie
else
require 'slf4r/wrapped_logger'
logger = (Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger)
- logger.info("setup slf4r logger wrapper with #{logger.inspect}")
+ logger.info("setup slf4r logger wrapper with #{logger.class}")
end
end
View
16 pom.xml
@@ -49,7 +49,7 @@
<dependency>
<groupId>rubygems</groupId>
<artifactId>rspec</artifactId>
- <version>1.3.0</version>
+ <version>1.3.1</version>
<type>gem</type>
<scope>test</scope>
</dependency>
@@ -67,6 +67,20 @@
<type>gem</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>rubygems</groupId>
+ <artifactId>cucumber</artifactId>
+ <version>0.9.4</version>
+ <type>gem</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>rubygems</groupId>
+ <artifactId>rails</artifactId>
+ <version>3.0.1</version>
+ <type>gem</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
View
@@ -20,7 +20,9 @@ Gem::Specification.new do |s|
s.files += Dir['lib/**/*']
s.files += Dir['spec/**/*']
s.test_files += Dir['spec/**/*_spec.rb']
- s.add_development_dependency 'rspec', '1.3.0'
+ s.add_development_dependency 'rspec', '1.3.1'
s.add_development_dependency 'logging', '1.4.1'
s.add_development_dependency 'log4r', '1.1.7'
+ s.add_development_dependency 'cucumber', '0.9.4'
+ s.add_development_dependency 'rails', '3.0.1'
end
View
@@ -0,0 +1,33 @@
+#-*- mode: ruby -*-
+
+def exec(command)
+ ruby = (defined? JRUBY_VERSION) ? "jruby" : "ruby"
+ run "#{ruby} #{command}"
+end
+
+def run_rake(arg, output = nil, options = {})
+ if output.is_a? Hash
+ options = output
+ output = nil
+ end
+ env = options[:env] || 'development'
+ rake_command = "#{ENV['GEM_HOME']}/bin/rake"
+ rake_command = "-S rake" unless File.exists?(rake_command)
+ exec "#{rake_command} #{arg} RAILS_ENV=#{env}#{output ? ' > ' + output : ''}"
+end
+
+def run_generate(*args)
+ command = "#{ENV['GEM_HOME']}/bin/rails"
+ command = "-S rails" unless File.exists?(command)
+ exec "#{command} generate #{args.join(' ')} >> error.txt"
+end
+
+def run_mvn(goal, *args)
+ run "mvn de.saumya.mojo:rails3-maven-plugin:0.23.0-SNAPSHOT:#{goal} #{args.join(' ')} -Dgem.home=#{ENV['GEM_HOME']} -Dgem.path=#{ENV['GEM_PATH']} >> error.txt"
+end
+
+def bundle_install
+ if defined? JRUBY_VERSION
+# run "unset GEM_HOME; unset GEM_PATH;rmvn gem:initialize -Dgem.home=#{ENV['GEM_HOME']} -Dgem.path=#{ENV['GEM_PATH']}"
+ end
+end
View
@@ -0,0 +1,28 @@
+#-*- mode: ruby -*-
+db_gem_line = "gem '#{gem_for_database}'"
+db_gem_line << ", :require => '#{require_for_database}'" if require_for_database
+db_gem_regexp = Regexp::quote(db_gem_line).gsub("'", "['\"]")
+jdbc_db = case options[:database]
+ when /postgresql/
+ "postgres"
+ when /mysql2/
+ "mysql"
+ when /mysql|sqlite3/
+ options[:database]
+ end
+jdbc_gem_line = "\n gem 'jdbc-#{jdbc_db}', :require => false" if jdbc_db
+
+gsub_file "Gemfile", /^#{db_gem_regexp}\w*$/, <<DB
+if defined?(JRUBY_VERSION)
+ gem 'activerecord-jdbc-adapter'#{jdbc_gem_line}
+else
+ #{db_gem_line}
+end
+DB
+
+# Avoid MySQL2 option for Rails 3
+if options[:database] =~ /mysql/
+ gsub_file "config/database.yml", /mysql2/, 'mysql'
+end
+
+# vim: syntax=Ruby
View
@@ -0,0 +1,11 @@
+#-*- mode: ruby -*-
+apply File.join(File.dirname(__FILE__), 'slf4r.template')
+
+require File.join(File.dirname(__FILE__), 'helper.rb')
+
+run_mvn 'pom'
+run_mvn 'generate', '-Dargs=slf4r:log4j'
+run_mvn 'pom', '-Drails.pom.force'
+run_mvn 'generate'
+
+# vim: syntax=Ruby
View
@@ -0,0 +1,13 @@
+#-*- mode: ruby -*-
+apply File.join(File.dirname(__FILE__), 'slf4r.template')
+
+require File.join(File.dirname(__FILE__), 'helper.rb')
+
+gem 'logging'
+
+run_mvn 'pom'
+run_mvn 'generate', '-Dargs=slf4r:logging'
+run_mvn 'pom'
+run_mvn 'generate'
+
+# vim: syntax=Ruby
@@ -0,0 +1,9 @@
+#-*- mode: ruby -*-
+apply File.join(File.dirname(__FILE__), 'slf4r.template')
+
+require File.join(File.dirname(__FILE__), 'helper.rb')
+
+run_mvn "pom"
+run_mvn "generate"
+
+# vim: syntax=Ruby
View
@@ -0,0 +1,6 @@
+#-*- mode: ruby -*-
+if defined? JRUBY_VERSION
+ apply File.join(File.dirname(__FILE__), 'jruby.template')
+end
+gem 'slf4r'
+# vim: syntax=Ruby

0 comments on commit 7737ebf

Please sign in to comment.