Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Added initializer for cucumber as well
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmeyer committed Mar 28, 2016
1 parent e11d907 commit ec34ae5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
16 changes: 16 additions & 0 deletions features/cli/init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ Feature: Initialize project with "proxy_rb"
0 examples, 0 failures
"""
Scenario: Create files for Cucumber
When I successfully run `proxy_rb init --test-framework cucumber`
And the file "features/support/proxy_rb.rb" should contain:
"""
require 'proxy_rb/cucumber'
"""
And the file "Gemfile" should contain:
"""
gem 'proxy_rb'
"""
When I successfully run `rspec`
Then the output should contain:
"""
0 examples, 0 failures
"""
Scenario: Unknown Test Framework
When I run `proxy_rb init --test-framework unknown`
Then the output should contain:
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy_rb/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def console
end

desc 'init', 'Initialize proxy_rb'
option :test_framework, default: 'rspec', enum: %w(rspec), desc: 'Choose which test framework to use'
option :test_framework, default: 'rspec', enum: %w(rspec cucumber), desc: 'Choose which test framework to use'
def init
ProxyRb::Initializer.new.call(options[:test_framework])
end
Expand Down
51 changes: 28 additions & 23 deletions lib/proxy_rb/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,6 @@ def add_gem
end
end

# ProxyRb
module ProxyRb
# Initializers
module Initializers
# Default Initializer
#
# This handles invalid values for initializer.
#
# @private
class FailingInitializer
class << self
def match?(*)
true
end

def start(*)
raise ArgumentError, %(Unknown test framework. Please use "rspec" )
end
end
end
end
end

# ProxyRb
module ProxyRb
# Initializer
Expand Down Expand Up @@ -98,6 +75,33 @@ def create_support_file
end
end

# ProxyRb
module ProxyRb
# Initializer
module Initializers
# Add proxy_rb + rspec to project
#
# @private
class CucumberInitializer < Thor::Group
include Thor::Actions

no_commands do
def self.match?(framework)
:cucumber == framework.downcase.to_sym
end
end

def create_helper; end

def create_support_file
create_file 'features/support/proxy_rb.rb', <<~EOS
require 'proxy_rb/cucumber'
EOS
end
end
end
end

# ProxyRb
module ProxyRb
# The whole initializer
Expand All @@ -115,6 +119,7 @@ class Initializer
def initialize
@initializers = []
@initializers << Initializers::RSpecInitializer
@initializers << Initializers::CucumberInitializer
end

# Create files etc.
Expand Down

0 comments on commit ec34ae5

Please sign in to comment.