Skip to content
Browse files

Initial import.

  • Loading branch information...
0 parents commit 7148eb9882218cdde3804dfc6be15ba1b5d5b5c5 @david committed
3 Generators
@@ -0,0 +1,3 @@
+scope 'merb-gen' do
+ Merb.add_generators File.join(File.dirname(__FILE__), 'lib', 'generators', 'cucumber')
+end
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 David Leal
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 README
@@ -0,0 +1,4 @@
+merb_cucumber
+=============
+
+A plugin for the Merb framework that provides ...
52 Rakefile
@@ -0,0 +1,52 @@
+require 'rubygems'
+require 'rake/gempackagetask'
+
+require 'merb-core'
+require 'merb-core/tasks/merb'
+
+GEM_NAME = "merb_cucumber"
+GEM_VERSION = "0.0.1"
+AUTHOR = "David Leal"
+EMAIL = "dgleal@gmail.com"
+HOMEPAGE = "http://github.com/david/merb_cucumber"
+SUMMARY = "Cucumber integration for Merb"
+
+spec = Gem::Specification.new do |s|
+ s.rubyforge_project = 'merb'
+ s.name = GEM_NAME
+ s.version = GEM_VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
+ s.summary = SUMMARY
+ s.description = s.summary
+ s.author = AUTHOR
+ s.email = EMAIL
+ s.homepage = HOMEPAGE
+ s.add_dependency('merb', '>= 0.9.9')
+ s.add_dependency('cucumber', '>= 0.1.7')
+ s.require_path = 'lib'
+ s.files = %w(LICENSE README Rakefile TODO Generators) + Dir.glob("{lib,spec}/**/*")
+
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
+
+desc "install the plugin as a gem"
+task :install do
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
+end
+
+desc "Uninstall the gem"
+task :uninstall do
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
+end
+
+desc "Create a gemspec file"
+task :gemspec do
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
+ file.puts spec.to_ruby
+ end
+end
3 TODO
@@ -0,0 +1,3 @@
+TODO:
+Detect the ORM
+Handle World, according to the ORM
17 lib/generators/cucumber.rb
@@ -0,0 +1,17 @@
+module Merb::Generators
+ class CucumberGenerator < Generator
+ def self.source_root
+ File.join(File.dirname(__FILE__), 'cucumber', 'templates')
+ end
+
+ template(:env) { |t| t.source = t.destination = "features/env.rb" }
+ template(:common_webrat) { |t| t.source = t.destination = "features/steps/common_webrat.rb" }
+ template(:cucumber, :after => :chmod) { |t| t.source = t.destination = "bin/cucumber" }
+
+ def chmod(action)
+ File.chmod(0755, action.destination)
+ end
+ end
+
+ add :cucumber, CucumberGenerator
+end
15 lib/generators/cucumber/templates/bin/cucumber
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'minigems'
+rescue LoadError
+ require 'rubygems'
+end
+
+if File.directory?(gems_dir = File.join(Dir.pwd, 'gems')) ||
+ File.directory?(gems_dir = File.join(File.dirname(__FILE__), '..', 'gems'))
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
+end
+
+require 'cucumber/cli'
+Cucumber::CLI.execute
13 lib/generators/cucumber/templates/features/env.rb
@@ -0,0 +1,13 @@
+# Sets up the Merb environment for Cucumber (thanks to krzys and roman)
+require "rubygems"
+
+# Add the local gems dir if found within the app root; any dependencies loaded
+# hereafter will try to load from the local gems before loading system gems.
+if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
+end
+
+require "merb-core"
+require "spec"
+
+Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
42 lib/generators/cucumber/templates/features/steps/common_webrat.rb
@@ -0,0 +1,42 @@
+# Commonly used webrat steps
+# http://github.com/brynary/webrat
+
+When /^I press "(.*)"$/ do |button|
+ clicks_button(button)
+end
+
+When /^I follow "(.*)"$/ do |link|
+ clicks_link(link)
+end
+
+When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
+ fills_in(field, :with => value)
+end
+
+When /^I select "(.*)" from "(.*)"$/ do |value, field|
+ selects(value, :from => field)
+end
+
+When /^I check "(.*)"$/ do |field|
+ checks(field)
+end
+
+When /^I uncheck "(.*)"$/ do |field|
+ unchecks(field)
+end
+
+When /^I choose "(.*)"$/ do |field|
+ chooses(field)
+end
+
+When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
+ attaches_file(field, path)
+end
+
+Then /^I should see "(.*)"$/ do |text|
+ response.body.should =~ /#{text}/m
+end
+
+Then /^I should not see "(.*)"$/ do |text|
+ response.body.should_not =~ /#{text}/m
+end
9 lib/merb_cucumber.rb
@@ -0,0 +1,9 @@
+if defined?(Merb::Plugins)
+ Merb::Plugins.add_rakefiles "merb_cucumber" / "merbtasks"
+
+ if Merb.environment == "test"
+ Merb::BootLoader.after_app_loads do
+ require File.join(File.dirname(__FILE__) / "merb_cucumber" / "feature")
+ end
+ end
+end
2 lib/merb_cucumber/feature.rb
@@ -0,0 +1,2 @@
+module Merb::Test
+end
10 lib/merb_cucumber/merbtasks.rb
@@ -0,0 +1,10 @@
+require 'cucumber/rake/task'
+
+Cucumber::Rake::Task::BINARY = Merb.root / 'bin' / 'cucumber'
+Cucumber::Rake::Task.new(:features) do |t|
+ t.cucumber_opts = "--format pretty"
+end
+
+if defined?(DataMapper)
+ task :features => 'db:automigrate'
+end

0 comments on commit 7148eb9

Please sign in to comment.
Something went wrong with that request. Please try again.