Skip to content
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

Error messages for generator #111

Open
wants to merge 1 commit 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
6 changes: 5 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ In your app's `Gemfile`, in the `group :test` section, add:
Then run:

bundle
rails generate machinist:install
rails generate machinist:install

Or (if you are using rspec)
bundle
rails generate machinist:install -t rspec

If you want Machinist to automatically add a blueprint to your blueprints file
whenever you generate a model, add the following to your `config/application.rb`
Expand Down
27 changes: 16 additions & 11 deletions lib/generators/machinist/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ module Machinist
module Generators #:nodoc:
class InstallGenerator < Rails::Generators::Base #:nodoc:
source_root File.expand_path('../templates', __FILE__)

class_option :test_framework, :type => :string, :aliases => "-t", :desc => "Test framework to use Machinist with"
class_option :cucumber, :type => :boolean, :desc => "Set up access to Machinist from Cucumber"
class_option :test_framework, :type => :string, :default => 'test_unit', :aliases => "-t", :desc => "Test framework to use Machinist with"
class_option :cucumber, :type => :boolean, :default => false, :desc => "Set up access to Machinist from Cucumber"

def blueprints_file
if rspec?
copy_file "blueprints.rb", "spec/support/blueprints.rb"
else
elsif test_unit?
copy_file "blueprints.rb", "test/blueprints.rb"
else
say_status(:error, "No test framework found. Please specify either 'rspec' or 'test_unit' with the -t option.", :red)
end
end

def test_helper
if test_unit?
inject_into_file("test/test_helper.rb", :after => "require 'rails/test_help'\n") do
"require File.expand_path(File.dirname(__FILE__) + '/blueprints')\n"
if test_unit?
if File.exist?("test/test_helper.rb")
inject_into_file("test/test_helper.rb", :after => "require 'rails/test_help'\n") do
"require File.expand_path(File.dirname(__FILE__) + '/blueprints')\n"
end
else
say_status(:warning, "Unable to modify the test_helper file. It does not exist.", :red)
end
end
end
Expand All @@ -31,11 +36,11 @@ def cucumber_support
private

def rspec?
options[:test_framework].to_sym == :rspec
options[:test_framework] and options[:test_framework].to_sym == :rspec
end

def test_unit?
options[:test_framework].to_sym == :test_unit
def test_unit?
options[:test_framework] and options[:test_framework].to_sym == :test_unit
end

def cucumber?
Expand Down