david-merb_cucumber 0.3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Generators ADDED
@@ -0,0 +1,3 @@
1
+ scope 'merb-gen' do
2
+ Merb.add_generators File.join(File.dirname(__FILE__), 'lib', 'generators', 'cucumber')
3
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 David Leal
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,33 @@
1
+ h1. merb_cucumber
2
+
3
+ Merb + Cucumber integration with Webrat support.
4
+
5
+ h2. Requirements
6
+
7
+ * merb-core >= 1.0
8
+ * cucumber >= 0.1.9
9
+ * webrat >= 0.3.1 (Optional)
10
+
11
+ h2. First Time
12
+
13
+ Inside your merb project root, run
14
+
15
+ $ merb-gen cucumber
16
+
17
+ For Webrat support, run
18
+
19
+ $ merb-gen cucumber --session-type webrat
20
+
21
+ This will also install a sample login feature that should pass if you're using merb-auth.
22
+
23
+ h2. Usage
24
+
25
+ To execute all the features run
26
+
27
+ $ rake features
28
+
29
+ h2. Notes
30
+
31
+ * When you are implementing the steps of an scenario, please use the new request test helper, if you try to use the
32
+ dispatch_to method, it won't work as expected.
33
+ * Webrat methods other than 'visits' are now singular only.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb_cucumber"
8
+ GEM_VERSION = "0.3.1.1"
9
+ AUTHOR = ["Roman Gonzalez", "David Leal"]
10
+ EMAIL = ["romanandreg@gmail.com", "dgleal@gmail.com"]
11
+ HOMEPAGE = "http://github.com/david/merb_cucumber"
12
+ SUMMARY = "Cucumber integration for Merb"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.rubyforge_project = 'merb'
16
+ s.name = GEM_NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.authors = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.add_dependency('merb-core', '~> 1.0')
27
+ s.add_dependency('cucumber', '>= 0.1.9')
28
+ s.require_path = 'lib'
29
+ s.files = %w(LICENSE README.textile Rakefile TODO Generators) + Dir.glob("{lib,spec}/**/*")
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ desc "install the plugin as a gem"
37
+ task :install do
38
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
39
+ end
40
+
41
+ desc "Uninstall the gem"
42
+ task :uninstall do
43
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
44
+ end
45
+
46
+ desc "Create a gemspec file"
47
+ task :gemspec do
48
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
49
+ file.puts spec.to_ruby
50
+ end
51
+ end
52
+
53
+ require 'spec/rake/spectask'
54
+ require 'spec/rake/spectask'
55
+ require 'merb-core/test/tasks/spectasks'
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ TODO:
2
+ Fix the problem when reading generated files on /tmp on the CucumberGenerator spec
3
+ Start the documentation
@@ -0,0 +1,39 @@
1
+ module Merb::Generators
2
+
3
+ class CucumberGenerator < Generator
4
+
5
+ desc <<-DESC
6
+ Generates setup code for cucumber feature framework
7
+ DESC
8
+
9
+ def self.source_root
10
+ File.join(File.dirname(__FILE__), 'cucumber', 'templates')
11
+ end
12
+
13
+ option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
14
+ option :session_type, :default => :simple, :desc => 'Session type to use (one of: simple, webrat)'
15
+
16
+ template(:env) { |t| t.source = t.destination = "features/env.rb" }
17
+ template(:rake) { |t| t.source = t.destination = "lib/tasks/cucumber.rake" }
18
+ template(:autotest) { |t| t.source = t.destination = "autotest/cucumber_merb_rspec.rb" }
19
+ template(:common_result_steps) { |t| t.source = t.destination = "features/steps/common_result_steps.rb" }
20
+
21
+ template(:example_feature, :session_type => :webrat) { |t| t.source = t.destination = "features/login.feature" }
22
+ template(:example_feature_steps, :session_type => :webrat) do |t|
23
+ t.source = t.destination = "features/steps/login_steps.rb"
24
+ end
25
+ template(:common_webrat, :session_type => :webrat) do |t|
26
+ t.source = t.destination = "features/steps/common_webrat.rb"
27
+ end
28
+
29
+ template(:cucumber, :after => :chmod) { |t| t.source = t.destination = "bin/cucumber" }
30
+
31
+ def chmod(action)
32
+ File.chmod(0755, action.destination)
33
+ end
34
+
35
+ end
36
+
37
+ add :cucumber, CucumberGenerator
38
+
39
+ end
@@ -0,0 +1,2 @@
1
+ require File.join( File.dirname(__FILE__), 'merb_rspec' )
2
+ class Autotest::CucumberMerbRspec < Autotest::MerbRspec ; end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'minigems'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ end
8
+
9
+ if File.directory?(gems_dir = File.join(Dir.pwd, 'gems')) ||
10
+ File.directory?(gems_dir = File.join(File.dirname(__FILE__), '..', 'gems'))
11
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
12
+ end
13
+
14
+ require 'cucumber/cli'
15
+ Cucumber::CLI.execute
@@ -0,0 +1,23 @@
1
+ # Sets up the Merb environment for Cucumber (thanks to krzys and roman)
2
+ require "rubygems"
3
+
4
+ # Add the local gems dir if found within the app root; any dependencies loaded
5
+ # hereafter will try to load from the local gems before loading system gems.
6
+ if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
7
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
8
+ end
9
+
10
+ require "merb-core"
11
+ require "spec"
12
+ require "merb_cucumber/world/<%= session_type %>"
13
+ <% if orm == :datamapper -%>
14
+ require "merb_cucumber/helpers/datamapper"
15
+ <% elsif orm == :activerecord -%>
16
+ require "merb_cucumber/helpers/activerecord"
17
+ <% end -%>
18
+
19
+ # Uncomment if you want transactional fixtures
20
+ # Merb::Test::World::Base.use_transactional_fixtures
21
+
22
+ Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
23
+
@@ -0,0 +1,13 @@
1
+ Feature: Login
2
+ To ensure the safety of the application
3
+ A regular user of the system
4
+ Must authenticate before using the app
5
+
6
+ Scenario: Failed Login
7
+ Given I am not authenticated
8
+ When I go to /login
9
+ And I fill in "login" with "i_dont_exist"
10
+ And I fill in "password" with "and_i_dont_have_a_password"
11
+ And I press "Log In"
12
+ Then the login request should fail
13
+ Then I should see an error message
@@ -0,0 +1,15 @@
1
+ Then /^I should see "(.*)"$/ do |text|
2
+ response.body.should =~ /#{text}/m
3
+ end
4
+
5
+ Then /^I should not see "(.*)"$/ do |text|
6
+ response.body.should_not =~ /#{text}/m
7
+ end
8
+
9
+ Then /^I should see an? (\w+) message$/ do |message_type|
10
+ response.should have_xpath("//*[@class='#{message_type}']")
11
+ end
12
+
13
+ Then /^the (.*) ?request should fail/ do |_|
14
+ response.should_not be_successful
15
+ end
@@ -0,0 +1,38 @@
1
+ # Commonly used webrat steps
2
+ # http://github.com/brynary/webrat
3
+
4
+ When /^I go to (.*)$/ do |path|
5
+ visit path
6
+ end
7
+
8
+ When /^I press "(.*)"$/ do |button|
9
+ click_button(button)
10
+ end
11
+
12
+ When /^I follow "(.*)"$/ do |link|
13
+ click_link(link)
14
+ end
15
+
16
+ When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
17
+ fill_in(field, :with => value)
18
+ end
19
+
20
+ When /^I select "(.*)" from "(.*)"$/ do |value, field|
21
+ select(value, :from => field)
22
+ end
23
+
24
+ When /^I check "(.*)"$/ do |field|
25
+ check(field)
26
+ end
27
+
28
+ When /^I uncheck "(.*)"$/ do |field|
29
+ uncheck(field)
30
+ end
31
+
32
+ When /^I choose "(.*)"$/ do |field|
33
+ choose(field)
34
+ end
35
+
36
+ When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
37
+ attach_file(field, path)
38
+ end
@@ -0,0 +1,3 @@
1
+ Given /^I am not authenticated$/ do
2
+ # yay!
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'cucumber/rake/task'
2
+
3
+ cucumber_options = proc do |t|
4
+ t.binary = Merb.root / 'bin' / 'cucumber'
5
+ t.cucumber_opts = "--format pretty"
6
+ end
7
+
8
+ Cucumber::Rake::Task.new(:features, &cucumber_options)
9
+ Cucumber::Rake::FeatureTask.new(:feature, &cucumber_options)
10
+ namespace :merb_cucumber do
11
+ task :test_env do
12
+ Merb.start_environment(:environment => "test", :adapter => 'runner')
13
+ end
14
+ end
15
+
16
+ <% if orm == :datamapper %>
17
+ dependencies = ['merb_cucumber:test_env', 'db:automigrate']
18
+ task :features => dependencies
19
+ task :feature => dependencies
20
+ <% else %>
21
+ task :features => 'merb_cucumber:test_env'
22
+ task :feature => 'merb_cucumber:test_env'
23
+ <% end %>
File without changes
@@ -0,0 +1,39 @@
1
+ $main = self # This must be included in the env.rb file!
2
+
3
+ module Merb
4
+ module Test
5
+ module Helpers
6
+ module ActiveRecord
7
+ module ClassMethods
8
+ def use_transactional_fixtures
9
+ # Let's set a transaction on the ActiveRecord connection when starting a new scenario
10
+ $main.Before do
11
+ if ActiveRecord::Base.connection.respond_to?(:increment_open_transactions)
12
+ ActiveRecord::Base.connection.increment_open_transactions
13
+ else
14
+ ActiveRecord::Base.send :increment_open_transactions
15
+ end
16
+ ActiveRecord::Base.connection.begin_db_transaction
17
+ end
18
+
19
+ # Going with a rollback after every step in the scenario is executed
20
+ $main.After do
21
+ ActiveRecord::Base.connection.rollback_db_transaction
22
+ if ActiveRecord::Base.connection.respond_to?(:decrement_open_transactions)
23
+ ActiveRecord::Base.connection.decrement_open_transactions
24
+ else
25
+ ActiveRecord::Base.send :decrement_open_transactions
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ module World
34
+ module Base
35
+ extend Helpers::ActiveRecord::ClassMethods
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ $main = self # This must be included in the env.rb file!
2
+
3
+ module Merb
4
+ module Test
5
+ module Helpers
6
+ module DataMapper
7
+ module ClassMethods
8
+ def use_transactional_fixtures
9
+ $main.Before do
10
+ repository(:default) do
11
+ transaction = ::DataMapper::Transaction.new(repository)
12
+ transaction.begin
13
+ repository.adapter.push_transaction(transaction)
14
+ end
15
+ end
16
+
17
+ $main.After do
18
+ repository(:default) do
19
+ while repository.adapter.current_transaction
20
+ repository.adapter.current_transaction.rollback
21
+ repository.adapter.pop_transaction
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ module World
31
+ module Base
32
+ extend Helpers::DataMapper::ClassMethods
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,12 @@
1
+ module Merb
2
+ module Test
3
+ module World
4
+ module Base
5
+ include ::Merb::Test::Matchers
6
+ include ::Merb::Test::ControllerHelper
7
+ include ::Merb::Test::RouteHelper
8
+ include ::Merb::Test::ViewHelper
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+
3
+ module Merb
4
+ module Test
5
+ module World
6
+ class Simple
7
+ include Base
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ World do
14
+ Merb::Test::World::Simple.new
15
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+ require 'webrat'
3
+ require 'webrat/merb'
4
+
5
+ module Merb
6
+ module Test
7
+ module World
8
+ class Webrat
9
+ include Base
10
+ include ::Webrat::Methods
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ World do
17
+ Merb::Test::World::Webrat.new
18
+ end
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "common files generator", :shared => true do
4
+
5
+ it "should generate the features/env.rb file" do
6
+ @generator.should create('/tmp/features/env.rb')
7
+ end
8
+
9
+ it "should generate the bin/cucumber file" do
10
+ @generator.should create('/tmp/bin/cucumber')
11
+ end
12
+
13
+ it "should generate the autotest/cucumber_merb_rspec.rb file" do
14
+ @generator.should create('/tmp/autotest/cucumber_merb_rspec.rb')
15
+ end
16
+
17
+ it "should generate the features/steps/common_result_steps.rb file" do
18
+ @generator.should create('/tmp/features/steps/common_result_steps.rb')
19
+ end
20
+
21
+ it "should generate the lib/tasks/cucumber.rake" do
22
+ @generator.should create('/tmp/features/steps/common_result_steps.rb')
23
+ end
24
+
25
+ it "should render templates successfully" do
26
+ lambda { @generator.render! }.should_not raise_error
27
+ end
28
+
29
+
30
+ end
31
+
32
+ describe Merb::Generators::CucumberGenerator do
33
+
34
+ describe "with datamapper as the orm" do
35
+
36
+ before(:each) do
37
+ @generator = Merb::Generators::CucumberGenerator.new('/tmp', {:orm => :datamapper })
38
+ end
39
+
40
+ it_should_behave_like "common files generator"
41
+
42
+ it "should have a requirement to the datamapper helper" do
43
+ @generator.render!
44
+ # IO.read(@generator.template(:env).destination).should =~ %r[merb_cucumber/helpers/datamapper]
45
+ end
46
+
47
+ end
48
+
49
+ describe "with activerecord as the orm" do
50
+
51
+ before(:each) do
52
+ @generator = Merb::Generators::CucumberGenerator.new('/tmp', {:orm => :activerecord})
53
+ end
54
+
55
+ it_should_behave_like "common files generator"
56
+
57
+ it "should have a requirement to the activerecord helper" do
58
+ @generator.render!
59
+ # IO.read(@generator.template(:env).destination).should =~ %r[merb_cucumber/helpers/activerecord]
60
+ end
61
+
62
+ end
63
+
64
+ describe "on simple session" do
65
+
66
+ before(:each) do
67
+ @generator = Merb::Generators::CucumberGenerator.new('/tmp', {:orm => :datamapper})
68
+ end
69
+
70
+ it_should_behave_like "common files generator"
71
+
72
+ it "should not generate the features/login.feature file" do
73
+ @generator.should_not create('/tmp/features/login.feature')
74
+ end
75
+
76
+ it "should not generate the features/steps/common_webrat.rb file" do
77
+ @generator.should_not create('/tmp/features/steps/common_webrat.rb')
78
+ end
79
+
80
+ it "should have a requirement to the simple session type on the env.rb file" do
81
+ @generator.render!
82
+ # IO.read(@generator.template(:env).destination).should =~ %r[merb_cucumber/world/webrat]
83
+ end
84
+
85
+ end
86
+
87
+ describe "on webrat session" do
88
+
89
+ before(:each) do
90
+ @generator = Merb::Generators::CucumberGenerator.new('/tmp', {:orm => :datamapper, :session_type => :webrat})
91
+ end
92
+
93
+ it_should_behave_like "common files generator"
94
+
95
+ it "should generate the features/login.feature file" do
96
+ @generator.should create('/tmp/features/login.feature')
97
+ end
98
+
99
+ it "should generate the features/steps/common_webrat.rb file" do
100
+ @generator.should create('/tmp/features/steps/common_webrat.rb')
101
+ end
102
+
103
+ it "should have a requirement to the webrat session type on the env.rb file" do
104
+ @generator.render!
105
+ # IO.read(@generator.template(:env).destination).should =~ %r[merb_cucumber/world/webrat]
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,17 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'merb-core'
6
+ require 'ruby-debug'
7
+ require 'merb-gen'
8
+ require 'generators/cucumber'
9
+ require 'templater/spec/helpers'
10
+
11
+ Merb.disable(:initfile)
12
+
13
+ Spec::Runner.configure do |config|
14
+ config.include Templater::Spec::Helpers
15
+ end
16
+
17
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: david-merb_cucumber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Gonzalez
8
+ - David Leal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-11-13 00:00:00 -08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: merb-core
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.9
33
+ version:
34
+ description: Cucumber integration for Merb
35
+ email:
36
+ - romanandreg@gmail.com
37
+ - dgleal@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.textile
44
+ - LICENSE
45
+ - TODO
46
+ files:
47
+ - LICENSE
48
+ - README.textile
49
+ - Rakefile
50
+ - TODO
51
+ - Generators
52
+ - lib/merb_cucumber.rb
53
+ - lib/generators
54
+ - lib/generators/cucumber
55
+ - lib/generators/cucumber/templates
56
+ - lib/generators/cucumber/templates/features
57
+ - lib/generators/cucumber/templates/features/steps
58
+ - lib/generators/cucumber/templates/features/steps/common_webrat.rb
59
+ - lib/generators/cucumber/templates/features/steps/common_result_steps.rb
60
+ - lib/generators/cucumber/templates/features/steps/login_steps.rb
61
+ - lib/generators/cucumber/templates/features/env.rb
62
+ - lib/generators/cucumber/templates/features/login.feature
63
+ - lib/generators/cucumber/templates/autotest
64
+ - lib/generators/cucumber/templates/autotest/cucumber_merb_rspec.rb
65
+ - lib/generators/cucumber/templates/bin
66
+ - lib/generators/cucumber/templates/bin/cucumber
67
+ - lib/generators/cucumber/templates/lib
68
+ - lib/generators/cucumber/templates/lib/tasks
69
+ - lib/generators/cucumber/templates/lib/tasks/cucumber.rake
70
+ - lib/generators/cucumber.rb
71
+ - lib/merb_cucumber
72
+ - lib/merb_cucumber/world
73
+ - lib/merb_cucumber/world/base.rb
74
+ - lib/merb_cucumber/world/simple.rb
75
+ - lib/merb_cucumber/world/webrat.rb
76
+ - lib/merb_cucumber/helpers
77
+ - lib/merb_cucumber/helpers/activerecord.rb
78
+ - lib/merb_cucumber/helpers/datamapper.rb
79
+ - spec/spec_helper.rb
80
+ - spec/cucumber_spec.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/david/merb_cucumber
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project: merb
103
+ rubygems_version: 1.2.0
104
+ signing_key:
105
+ specification_version: 2
106
+ summary: Cucumber integration for Merb
107
+ test_files: []
108
+