Skip to content

Feature/engine support (Issue #11) #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion features/support/rails_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ module RailsFixtures
end

private
def create_and_mount_engine(version = '3.2')
run 'bundle exec rails plugin new vendor/plugins/rails_engine --mountable'
stop_processes!
write_file('vendor/plugins/rails_engine/config/routes.rb', "
RailsEngine::Engine.routes.draw do
root to: redirect('/index.html')
end
")
append_to_file("Gemfile",
"gem 'rails_engine', :path => 'vendor/plugins/rails_engine'\n")
stop_processes!
run "bundle install"
stop_processes!
end

def create_rails_app(version = '3.2')
@aruba_timeout_seconds = 100
Expand All @@ -41,15 +55,16 @@ def create_rails_app(version = '3.2')
")
run "bundle install"
run "rm -fR rails_app"
stop_processes!
run 'bundle exec rails new rails_app'
stop_processes!
cd "rails_app"
write_file('config/routes.rb', "
RailsApp::Application.routes.draw do
root to: redirect('/index.html')
mount RailsEngine::Engine, :at => '/'
end
")
create_and_mount_engine(version)
end

def add_spinach_rails
Expand All @@ -64,12 +79,18 @@ def add_test_features
Scenario: Test scenario
Given I am running spinach
Then It should be all OK
Scenario: Mounted engine test scenario
Given the test app has mounted an engine
Then It should be all OK
")
write_file('features/steps/test_feature.rb',
"class TestFeature < Spinach::FeatureSteps
Given 'I am running spinach' do
visit root_path
end
Given 'the test app has mounted an engine' do
visit rails_engine.root_path
end
Then 'It should be all OK' do
page.has_content?('Rails').must_equal true
end
Expand Down
22 changes: 22 additions & 0 deletions lib/spinach-rails/generators/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ def create_environment_file

require 'minitest/spec'

module Spinach
class FeatureSteps
known_engines = Rails::Engine.descendants
engines_with_routes = known_engines.select{ |engine|
engine.respond_to?(:routes) && engine.routes.named_routes.routes.present?
}
engines_with_routes.each do |engine|
engine_name = engine.to_s.underscore.split("/")
case engine_name.pop
when "application"
send :define_method, :main_app do
engine.routes.url_helpers
end
when "engine"
send :define_method, engine_name[0].to_sym do
engine.routes.url_helpers
end
end
end
end
end

# require 'database_cleaner'
# DatabaseCleaner.strategy = :truncation
#
Expand Down