proxy_rb 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -4
  3. data/Gemfile +2 -2
  4. data/History.md +17 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +15 -4
  7. data/Rakefile +8 -2
  8. data/exe/proxy_rb +8 -0
  9. data/fixtures/empty/README.md +18 -0
  10. data/fixtures/empty/Rakefile +10 -0
  11. data/lib/proxy_rb/announcer.rb +162 -0
  12. data/lib/proxy_rb/{rspec/helpers → api}/.keep +0 -0
  13. data/lib/proxy_rb/api/core.rb +25 -0
  14. data/lib/proxy_rb/api/http_proxy.rb +94 -0
  15. data/lib/proxy_rb/api/passwords.rb +26 -0
  16. data/lib/proxy_rb/api.rb +19 -0
  17. data/lib/proxy_rb/basic_configuration/{in_config_wrapper.rb → in_configuration_wrapper.rb} +1 -1
  18. data/lib/proxy_rb/basic_configuration.rb +2 -2
  19. data/lib/proxy_rb/cli.rb +27 -0
  20. data/lib/proxy_rb/colorizer.rb +113 -0
  21. data/lib/proxy_rb/configuration.rb +1 -1
  22. data/lib/proxy_rb/configuration_wrapper.rb +59 -0
  23. data/lib/proxy_rb/console/help.rb +29 -0
  24. data/lib/proxy_rb/console.rb +62 -0
  25. data/lib/proxy_rb/credentials.rb +11 -0
  26. data/lib/proxy_rb/drivers/poltergeist_driver.rb +8 -2
  27. data/lib/proxy_rb/drivers/selenium_driver.rb +7 -1
  28. data/lib/proxy_rb/drivers/webkit_driver.rb +10 -1
  29. data/lib/proxy_rb/errors.rb +12 -0
  30. data/lib/proxy_rb/event_bus/name_resolver.rb +163 -0
  31. data/lib/proxy_rb/event_bus.rb +60 -0
  32. data/lib/proxy_rb/events.rb +34 -0
  33. data/lib/proxy_rb/http_proxy.rb +8 -0
  34. data/lib/proxy_rb/initializer.rb +132 -0
  35. data/lib/proxy_rb/{rspec/matchers → matchers}/.keep +0 -0
  36. data/lib/proxy_rb/matchers/be_forbidden.rb +14 -0
  37. data/lib/proxy_rb/matchers/be_successful.rb +14 -0
  38. data/lib/proxy_rb/matchers/have_mime_type.rb +9 -0
  39. data/lib/proxy_rb/password_fetchers/basic_password_fetcher.rb +25 -0
  40. data/lib/proxy_rb/password_fetchers/chaining_password_fetcher.rb +54 -0
  41. data/lib/proxy_rb/password_fetchers/environment_password_fetcher.rb +7 -1
  42. data/lib/proxy_rb/password_fetchers/vault_password_fetcher.rb +7 -1
  43. data/lib/proxy_rb/proxy_url.rb +8 -0
  44. data/lib/proxy_rb/request.rb +5 -21
  45. data/lib/proxy_rb/resource.rb +11 -7
  46. data/lib/proxy_rb/response.rb +5 -13
  47. data/lib/proxy_rb/rspec.rb +32 -13
  48. data/lib/proxy_rb/runtime.rb +49 -0
  49. data/lib/proxy_rb/setup.rb +60 -0
  50. data/lib/proxy_rb/version.rb +1 -1
  51. data/proxy_rb.gemspec +2 -2
  52. metadata +38 -29
  53. data/lib/proxy_rb/rspec/helpers/http_proxy.rb +0 -83
  54. data/lib/proxy_rb/rspec/helpers/passwords.rb +0 -29
  55. data/lib/proxy_rb/rspec/shared_contexts/.keep +0 -0
  56. data/lib/proxy_rb/rspec/shared_examples/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bc945043463fe4b3e69c8bdf8e125ef58aa8dce
4
- data.tar.gz: 35765821a441b1d9bbc016bd2c6672cf4c122ee6
3
+ metadata.gz: 0902f8cb548f1fa6b4180ed66ebf2dcd26edb71a
4
+ data.tar.gz: 3e29d77475f07c367318ca19daa7dc5160ba1bb0
5
5
  SHA512:
6
- metadata.gz: a9af5d4ece8df28ee2551e2dde1a2f3501081bdf5efcfc394201955528046adcbcfea9a4f39baa17bc0d4a032980b3e61aa44dee3191bccbb75717b8b06477e5
7
- data.tar.gz: 17309f5b430978403dcd7bd3fedeb86a25d2d4bfff0a873c6c0a42abe357b2c1d295861c8d48a235e2d047111e2a26014cf56032486dc76931d019ff4a7e176c
6
+ metadata.gz: 14b997bcbfbeb3abffda5dc16e0b04b8313431c4f34b896d3b4cd5f54bddec02c1a05f007ba5ec69d9454c52930d3a309c2ae01a8e157bda5004b77f83e7efa1
7
+ data.tar.gz: 06b90ebb03851f17c42ba372f92bb82c033622b341870338897a8c1c2ce599f40dfee891db95cf473887eb5f3ed96e28ce0ad7c12fd04ae6ea6265535010753f
data/.travis.yml CHANGED
@@ -4,16 +4,21 @@ env:
4
4
  language: ruby
5
5
  bundler_args: --without development debug profile
6
6
  rvm:
7
- - 2.1.8
8
- - 2.2.4
9
7
  - 2.3.0
10
8
  - ruby-head
11
9
  script: bin/test
12
10
  before_install:
13
11
  - curl -o /tmp/vault.zip https://releases.hashicorp.com/vault/0.5.1/vault_0.5.1_linux_amd64.zip
14
- - unzip /tmp/vault.zip
12
+ - unzip /tmp/vault.zip -d /tmp/
15
13
  - install -D -m 0755 /tmp/vault ./bin/vault
14
+ before_script:
15
+ - 'export DISPLAY=:99.0'
16
+ - 'sh -e /etc/init.d/xvfb start'
17
+ - sleep 3 # give xvfb some time to start
16
18
  addons:
17
19
  apt:
18
20
  packages:
19
- - libwebkit-dev
21
+ - libqtwebkit-dev
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -23,7 +23,7 @@ group :development, :test do
23
23
  # Set env during development/test
24
24
  gem 'dotenv'
25
25
 
26
- gem 'aruba', require: false
26
+ gem 'aruba', '~> 0.14.1', require: false
27
27
  gem 'awesome_print', require: 'ap'
28
28
  gem 'bundler', '~> 1.3', require: false
29
29
  gem 'command_exec', require: false
@@ -38,7 +38,7 @@ group :development, :test do
38
38
  gem 'launchy', require: false
39
39
  gem 'license_finder'
40
40
  gem 'rack'
41
- gem 'rake', require: false
41
+ gem 'rake', '~> 10.0', require: false
42
42
  gem 'rubocop', require: false
43
43
  gem 'simplecov', require: false
44
44
  gem 'sinatra', require: 'sinatra/base'
data/History.md ADDED
@@ -0,0 +1,17 @@
1
+ # UNRELEASED
2
+
3
+ ## [v0.5.0](https://github.com/cucumber/aruba/compare/v0.4.0...v0.5.0)
4
+
5
+ * Added initializer to bootstrap `proxy_prb`
6
+ * Improved documentation
7
+ * Improved test suite
8
+ * Made test suite succeed on travis.org
9
+ * Added announcer known from `aruba`. Now one output information about
10
+ configured user, proxy and resource
11
+ * Addd new matchers to output better error messages
12
+
13
+ # RELEASED
14
+
15
+ ## [v0.4.0](https://github.com/cucumber/aruba/compare/v0.1.0...v0.4.0)
16
+
17
+ * Added support for `poltergeist`, `selenium` and `webkit`
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016- Max Meyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -76,6 +76,10 @@ RSpec.describe 'My Proxy' do
76
76
  end
77
77
  ~~~
78
78
 
79
+ Please have a look at the
80
+ ["features/getting_started"](features/getting_started)-directory for more
81
+ information about that topic.
82
+
79
83
  ### Getting on with "proxy_rb"
80
84
 
81
85
  Please have a look at our "feature"-files found [here](features/).
@@ -85,14 +89,14 @@ Please have a look at our "feature"-files found [here](features/).
85
89
  Maybe your proxy servers require authentication and you would like to test this
86
90
  as well. You've got several possibilies to use proxy passwords with `proxy_rb`.
87
91
  Please have a look at
88
- ["features/authentication.feature"](features/authentication.feature) for
89
- detailed information.
92
+ ["features/proxy/authentication"](features/proxy/authentication) and
93
+ ["features/api/password"](features/api/password) for detailed information.
90
94
 
91
95
  ### Driver
92
96
 
93
- You can choose between two drivers to sent your requests: "Poltergeist" and
97
+ You can choose between three drivers to sent your requests: "Selenium", "Poltergeist" and
94
98
  "Webkit". Please have a look at
95
- ["features/drivers.feature"](features/drivers.feature) for detailed
99
+ ["features/drivers"](features/drivers) for detailed
96
100
  information.
97
101
 
98
102
  ## Development
@@ -128,3 +132,10 @@ release a new version, update the version number in `version.rb`, and then run
128
132
  `bundle exec rake gem:release` to create a git tag for the version, push git
129
133
  commits and tags, and push the `.gem` file to
130
134
  [rubygems.org](https://rubygems.org).
135
+
136
+ ## Caveats
137
+
138
+ * Authentication against a proxy using BASIC-scheme works fine for `Poltergeist` and `Webkit`-drivers. It fails for `Selenium` as you cannot pass username and password to the browser
139
+ * Authentication agains a proxy using NEGOTIATE (Kerberos) and NTLM-scheme fails for `Poltergeist` and `Webkit`-drivers due to problems with Qt which is used by both projects
140
+
141
+
data/Rakefile CHANGED
@@ -20,8 +20,9 @@ desc 'Test with coveralls'
20
20
  task coveralls: %w(test coveralls:push)
21
21
 
22
22
  namespace :test do
23
- require 'rubocop/rake_task'
24
- RuboCop::RakeTask.new
23
+ task :rubocop do
24
+ sh 'rubocop'
25
+ end
25
26
 
26
27
  desc 'Run rspec'
27
28
  task :rspec do
@@ -33,3 +34,8 @@ namespace :test do
33
34
  sh 'bundle exec cucumber -p all'
34
35
  end
35
36
  end
37
+
38
+ desc 'Remove files in tmp'
39
+ task :clobber do
40
+ rm_rf Dir.glob(File.expand_path('../tmp/*', __FILE__))
41
+ end
data/exe/proxy_rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
5
+
6
+ require 'proxy_rb/cli'
7
+
8
+ ProxyRb::Cli.start
@@ -0,0 +1,18 @@
1
+ # Simple proxy configuration project
2
+
3
+ This is a simple proxy configuration project
4
+
5
+ ## Boostrap
6
+
7
+ Execute:
8
+
9
+ $ bundle
10
+
11
+ ## Usage
12
+
13
+ Place files in `spec/` and run `rspec`.
14
+
15
+ ### Fixture
16
+
17
+ This fixture includes files for `rspec`-integration.
18
+
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ namespace :gem do
3
+ require 'bundler/gem_tasks'
4
+ end
5
+
6
+ task default: :test
7
+
8
+ task :test do
9
+ sh 'rspec'
10
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+ require 'shellwords'
3
+ require 'proxy_rb/colorizer'
4
+
5
+ ProxyRb::AnsiColor.coloring = false if !STDOUT.tty? && !ENV.key?('AUTOTEST')
6
+
7
+ # ProxyRb
8
+ module ProxyRb
9
+ # Announcer
10
+ #
11
+ # @private
12
+ #
13
+ # @example Activate your you own channel in cucumber
14
+ #
15
+ # Before('@announce-my-channel') do
16
+ # aruba.announcer.activate :my_channel
17
+ # end
18
+ #
19
+ # @example Activate your you own channel in rspec > 3
20
+ #
21
+ # before do
22
+ # current_example = context.example
23
+ # aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
24
+ # end
25
+ #
26
+ # ProxyRb.announcer.announce(:my_channel, 'my message')
27
+ #
28
+ class Announcer
29
+ # Announcer using Kernel.puts
30
+ class KernelPutsAnnouncer
31
+ def announce(message)
32
+ Kernel.puts message
33
+ end
34
+
35
+ def mode?(m)
36
+ :kernel_puts == m
37
+ end
38
+ end
39
+
40
+ # Announcer using Main#puts
41
+ class PutsAnnouncer
42
+ def announce(message)
43
+ puts message
44
+ end
45
+
46
+ def mode?(m)
47
+ :puts == m
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :announcers, :announcer, :channels, :output_formats, :colorizer
54
+
55
+ public
56
+
57
+ def initialize(*args)
58
+ @announcers = []
59
+ @announcers << PutsAnnouncer.new
60
+ @announcers << KernelPutsAnnouncer.new
61
+
62
+ @colorizer = ProxyRb::Colorizer.new
63
+
64
+ @announcer = @announcers.first
65
+ @channels = {}
66
+ @output_formats = {}
67
+
68
+ @options = args[1] || {}
69
+
70
+ after_init
71
+ end
72
+
73
+ private
74
+
75
+ def after_init
76
+ output_format :proxy, proc { |v| format('Proxy: %s', v) }
77
+ output_format :proxy_user, proc { |v| format('Proxy User: %s', v) }
78
+ output_format :resource_user, proc { |v| format('Resource User: %s', v) }
79
+ output_format :resource, proc { |v| format('Resource: %s', v) }
80
+ end
81
+
82
+ def output_format(channel, string = '%s', &block)
83
+ output_formats[channel.to_sym] = if block_given?
84
+ block
85
+ elsif string.is_a?(Proc)
86
+ string
87
+ else
88
+ proc { |*args| format(string, *args) }
89
+ end
90
+ end
91
+
92
+ public
93
+
94
+ # Reset announcer
95
+ def reset
96
+ @announcer = @announcers.first
97
+ end
98
+
99
+ # Change mode of announcer
100
+ #
101
+ # @param [Symbol] m
102
+ # The mode to set
103
+ def mode=(m)
104
+ @announcer = @announcers.find { |_a| f.mode? m.to_sym }
105
+
106
+ self
107
+ end
108
+
109
+ # Check if channel is activated
110
+ #
111
+ # @param [Symbol] channel
112
+ # The name of the channel to check
113
+ def activated?(channel)
114
+ channels[channel.to_sym] == true
115
+ end
116
+
117
+ # Activate a channel
118
+ #
119
+ # @param [Symbol] channel
120
+ # The name of the channel to activate
121
+ def activate(*chns)
122
+ chns.flatten.each { |c| channels[c.to_sym] = true }
123
+
124
+ self
125
+ end
126
+
127
+ # Announce information to channel
128
+ #
129
+ # @param [Symbol] channel
130
+ # The name of the channel to check
131
+ #
132
+ # @param [Array] args
133
+ # Arguments
134
+ #
135
+ # @yield
136
+ # If block is given, that one is called and the return value is used as
137
+ # message to be announced.
138
+ def announce(channel, *args, &_block)
139
+ channel = channel.to_sym
140
+
141
+ the_output_format = if output_formats.key? channel
142
+ output_formats[channel]
143
+ else
144
+ proc { |v| format('%s', v) }
145
+ end
146
+
147
+ return unless activated?(channel)
148
+
149
+ message = if block_given?
150
+ the_output_format.call(yield)
151
+ else
152
+ the_output_format.call(*args)
153
+ end
154
+ message += "\n"
155
+ message = colorizer.cyan(message)
156
+
157
+ announcer.announce(message)
158
+
159
+ nil
160
+ end
161
+ end
162
+ end
File without changes
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'proxy_rb/runtime'
3
+ require 'proxy_rb/setup'
4
+
5
+ # Main Module
6
+ module ProxyRb
7
+ # Api
8
+ module Api
9
+ # Core Module
10
+ module Core
11
+ # Aruba Runtime
12
+ def proxy_rb
13
+ @_proxy_rb_runtime ||= Runtime.new
14
+ end
15
+
16
+ # Setup everything to make proxy_rb work
17
+ #
18
+ def setup_proxy_rb
19
+ ProxyRb::Setup.new(proxy_rb).call
20
+
21
+ nil
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'proxy_rb'
4
+ require 'proxy_rb/resource'
5
+ require 'proxy_rb/http_downloader'
6
+ require 'proxy_rb/http_proxy'
7
+ require 'proxy_rb/request'
8
+ require 'proxy_rb/response'
9
+ require 'proxy_rb/errors'
10
+
11
+ # Main Module
12
+ module ProxyRb
13
+ # Api
14
+ module Api
15
+ # Non includable internal helper methods
16
+ #
17
+ # Not for use by normal users
18
+ module NonIncludes
19
+ class << self
20
+ def clear_environment
21
+ %w(
22
+ http_proxy
23
+ https_proxy
24
+ HTTP_PROXY
25
+ HTTPS_PROXY
26
+ ).each { |v| ENV.delete v }
27
+ end
28
+
29
+ def configure_driver
30
+ ProxyRb.config.driver.configure_driver
31
+ end
32
+
33
+ def register_capybara_driver_for_proxy(proxy)
34
+ ProxyRb.config.driver.register proxy
35
+ end
36
+ end
37
+ end
38
+
39
+ # For http proxy
40
+ module HttpProxy
41
+ include ::Capybara::DSL
42
+
43
+ # The proxy based on subject
44
+ def proxy
45
+ ProxyRb::HttpProxy.new(ProxyUrlParser.new(subject))
46
+ end
47
+
48
+ # Visit an URL
49
+ #
50
+ # @param [String] url
51
+ # rubocop:disable Metrics/AbcSize
52
+ def visit(url)
53
+ resource = Resource.new(url)
54
+
55
+ proxy_rb.event_bus.notify Events::ResourceSet.new(resource.url.to_s)
56
+ proxy_rb.event_bus.notify Events::ResourceUserSet.new(resource.credentials.to_s) unless resource.credentials.empty?
57
+
58
+ NonIncludes.clear_environment
59
+ NonIncludes.configure_driver
60
+
61
+ proxy_rb.event_bus.notify Events::ProxySet.new(proxy.url.to_s)
62
+ proxy_rb.event_bus.notify Events::ProxyUserSet.new(proxy.credentials.to_s) unless proxy.credentials.empty?
63
+
64
+ NonIncludes.register_capybara_driver_for_proxy(proxy)
65
+
66
+ begin
67
+ super(resource.to_s)
68
+ rescue *ProxyRb.config.driver.timeout_errors
69
+ raise ProxyRb::UrlTimeoutError, "Failed to fetch #{resource}: Timeout occured."
70
+ rescue *ProxyRb.config.driver.failure_errors => e
71
+ raise ProxyRb::ResourceNotDownloadableError, "Failed to fetch #{resource}: #{e.message}."
72
+ rescue => e
73
+ raise ProxyRb::ResourceNotDownloadableError, "An unexpected error occured while fetching #{resource}: #{e.message}."
74
+ end
75
+ end
76
+ # rubocop:enable Metrics/AbcSize
77
+
78
+ # !@method download
79
+ #
80
+ # @see #visit
81
+ alias download visit
82
+
83
+ # Get access to the request made
84
+ def request
85
+ Request.new(page)
86
+ end
87
+
88
+ # Get access to the response get
89
+ def response
90
+ Response.new(page)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require 'contracts'
3
+
4
+ # ProxyRb
5
+ module ProxyRb
6
+ # Api
7
+ module Api
8
+ # Helpers to access passwords
9
+ module Passwords
10
+ include Contracts::Core
11
+ include Contracts::Builtin
12
+
13
+ Contract Or[String, Symbol] => Maybe[String]
14
+ # Get password for user
15
+ #
16
+ # @param [String] user_name
17
+ # The user name
18
+ #
19
+ # @return [String]
20
+ # The password
21
+ def password(user_name)
22
+ ProxyRb.config.password_fetcher.call(user_name.to_s)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'rspec/matchers'
3
+ require 'capybara/rspec'
4
+
5
+ require 'proxy_rb/no_proxy'
6
+ require 'proxy_rb/main'
7
+ ProxyRb.require_files_matching_pattern('api/*.rb')
8
+ ProxyRb.require_files_matching_pattern('matchers/*.rb')
9
+
10
+ # ProxyRb
11
+ module ProxyRb
12
+ # Api
13
+ module Api
14
+ include ProxyRb::Api::Core
15
+ include ProxyRb::Api::HttpProxy
16
+ include ProxyRb::Api::Passwords
17
+ include Capybara::RSpecMatchers
18
+ end
19
+ end
@@ -9,7 +9,7 @@ module ProxyRb
9
9
  # configuration option from with `ProxyRb::Config`.
10
10
  #
11
11
  # @private
12
- class InConfigWrapper
12
+ class InConfigurationWrapper
13
13
  attr_reader :config
14
14
  private :config
15
15
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'contracts'
3
3
  require 'proxy_rb/basic_configuration/option'
4
- require 'proxy_rb/basic_configuration/in_config_wrapper'
4
+ require 'proxy_rb/basic_configuration/in_configuration_wrapper'
5
5
 
6
6
  # ProxyRb
7
7
  module ProxyRb
@@ -35,7 +35,7 @@ module ProxyRb
35
35
  raise ArgumentError, 'contract-options is required' if contract.nil?
36
36
 
37
37
  Contract contract
38
- add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
38
+ add_option(name, block_given? ? yield(InConfigurationWrapper.new(known_options)) : default)
39
39
 
40
40
  define_method(name) { find_option(name).value }
41
41
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ require 'thor'
3
+ require 'proxy_rb/console'
4
+ require 'proxy_rb/initializer'
5
+
6
+ # ProxyRb
7
+ module ProxyRb
8
+ # Command line Interface
9
+ #
10
+ # @private
11
+ class Cli < Thor
12
+ def self.exit_on_failure?
13
+ true
14
+ end
15
+
16
+ desc 'console', "Start proxy_rb's console"
17
+ def console
18
+ ProxyRb::Console.new.start
19
+ end
20
+
21
+ desc 'init', 'Initialize proxy_rb'
22
+ option :test_framework, default: 'rspec', enum: %w(rspec), desc: 'Choose which test framework to use'
23
+ def init
24
+ ProxyRb::Initializer.new.call(options[:test_framework])
25
+ end
26
+ end
27
+ end