diff --git a/features/cli/init.feature b/features/cli/init.feature index 5932e15..7c5065c 100644 --- a/features/cli/init.feature +++ b/features/cli/init.feature @@ -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: diff --git a/lib/proxy_rb/cli.rb b/lib/proxy_rb/cli.rb index a005ed2..250ddc5 100644 --- a/lib/proxy_rb/cli.rb +++ b/lib/proxy_rb/cli.rb @@ -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 diff --git a/lib/proxy_rb/initializer.rb b/lib/proxy_rb/initializer.rb index 44f7e6d..8a4f383 100644 --- a/lib/proxy_rb/initializer.rb +++ b/lib/proxy_rb/initializer.rb @@ -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 @@ -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 @@ -115,6 +119,7 @@ class Initializer def initialize @initializers = [] @initializers << Initializers::RSpecInitializer + @initializers << Initializers::CucumberInitializer end # Create files etc.