Skip to content

Commit

Permalink
reorganize test/test_helper.rb and features/env.rb files so that the …
Browse files Browse the repository at this point in the history
…engine generator works better for engines outside of the adva-cms2 repository

should probably make things completely independend from hardcoded load paths
  • Loading branch information
Sven Fuchs committed Jan 25, 2011
1 parent 5a91a0f commit 260c460
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 25 deletions.
3 changes: 2 additions & 1 deletion adva-blog/features/env.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

4 changes: 3 additions & 1 deletion adva-blog/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)


2 changes: 1 addition & 1 deletion adva-cache/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

# require Adva::Cache.root.join('lib/testing/test_helper')
# World(TestHelper::Cache)
Expand Down
4 changes: 3 additions & 1 deletion adva-cache/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)


2 changes: 1 addition & 1 deletion adva-categories/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

4 changes: 2 additions & 2 deletions adva-categories/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)


require 'adva-categories'
20 changes: 14 additions & 6 deletions adva-core/lib/adva/generators/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module Adva
module Generators
class Engine < Rails::Generators::Base
source_root File.expand_path('../templates/engine', __FILE__)

attr_reader :name

def initialize(name, options = {})
@name = name
super()
end

def build
empty_directory "adva-#{name}"
template "gemspec.erb", "adva-#{name}/adva-#{name}.gemspec"
Expand All @@ -31,15 +31,23 @@ def build
empty_directory "adva-#{name}/db/migrate"
template 'migration.rb.erb', "adva-#{name}/db/migrate/#{migration_timestamp}_adva_#{name}_create_tables.rb"

empty_directory "adva-#{name}/features"
template 'env.rb', "adva-#{name}/features/env.rb"
template 'feature.erb', "adva-#{name}/features/#{name}.feature"

empty_directory "adva-#{name}/lib/adva"
create_file "adva-#{name}/lib/adva-#{name}.rb", "require 'adva/#{name}'"
template 'engine.rb.erb', "adva-#{name}/lib/adva/#{name}.rb"

empty_directory "adva-#{name}/lib/testing"
create_file "adva-#{name}/lib/paths.rb", "adva-#{name}/lib/step_definitions.rb"
template 'paths.rb.erb', "adva-#{name}/lib/testing/paths.rb"

empty_directory "adva-#{name}/test"
template 'all.rb', "adva-#{name}/test/all.rb"
template 'test_helper.rb.erb', "adva-#{name}/test/test_helper.rb"
end

protected

def migration_timestamp
Expand All @@ -49,10 +57,10 @@ def migration_timestamp
def table_name
name.tableize
end

def class_name
name.camelize
end
end
end
end
end
3 changes: 3 additions & 0 deletions adva-core/lib/adva/generators/templates/engine/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path('../../../features/env', __FILE__)


3 changes: 3 additions & 0 deletions adva-core/lib/adva/generators/templates/engine/feature.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Feature: <%= name.titleize %>

Scenario:
12 changes: 12 additions & 0 deletions adva-core/lib/adva/generators/templates/engine/paths.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Adva::<%= name.classify %>::Paths
def path_to(page)
case page
when 'path/to/<%= name %>'
else
super
end
end
end
World(Adva::<%= name.classify %>::Paths)


Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)

require 'adva-<%= name %>'
10 changes: 6 additions & 4 deletions adva-core/lib/testing/helpers/global_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module GlobalHelpers

def site
Site.first || raise("Could not find a site. Maybe you want to set one up in your story background?")
end

def user
@user || raise("@current_user is not set. Maybe you want to sign in first?")
end

def account
Account.first || raise("Could not find a site. Maybe you want to set one up in your story background?")
end

def parsed_html
# memoizing this causes problems since it seems to be memoized across requests
# TODO: Figure out way to memoize within one request only
# @parsed_body ||= Nokogiri::HTML(response.body)
Nokogiri::HTML(response.body)
end

end
end
2 changes: 1 addition & 1 deletion adva-core/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def setup
def teardown
DatabaseCleaner.clean
end
end
end
2 changes: 1 addition & 1 deletion adva-markup/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

4 changes: 2 additions & 2 deletions adva-markup/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)


require 'adva-markup'
2 changes: 1 addition & 1 deletion adva-static/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

require Adva::Static.root.join('lib/testing/test_helper')
World(TestHelper::Static)
Expand Down
3 changes: 2 additions & 1 deletion adva-static/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require File.expand_path('../../../adva-core/test/test_helper', __FILE__)
require File.expand_path('../../../test/test_helper', __FILE__)

2 changes: 1 addition & 1 deletion adva-user/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require File.expand_path('../../../adva-core/lib/testing/env', __FILE__)
require File.expand_path('../../../features/env', __FILE__)

2 changes: 2 additions & 0 deletions adva-user/lib/testing/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Given /^I am signed in with "([^"]*)" and "([^"]*)"$/ do |email, password|
post user_session_path, :user => { :email => email, :password => password }
@user = User.find_by_email(email)
end

# This step should only be used for testing the login itself (login.feature)
Expand All @@ -10,6 +11,7 @@
fill_in 'Email', :with => email
fill_in 'Password', :with => password
click_button 'Sign in'
@user = User.find_by_email(email)
end

Given /a confirmed user with email "([^"]+)" and password "([^"]+)"/ do |email, password|
Expand Down
2 changes: 2 additions & 0 deletions features/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require File.expand_path('../../adva-core/lib/testing/env', __FILE__)

3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path('../../adva-core/test/test_helper', __FILE__)


0 comments on commit 260c460

Please sign in to comment.