class ProxyTester::Actions::AddExamplesToTestCasesDirectory

Attributes

examples_directory[R]
options[R]

Public Class Methods

new(examples_directory, options = {}) click to toggle source
# File lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb, line 11
def initialize(examples_directory, options = {})
  @examples_directory = examples_directory
  @options            = options
end

Public Instance Methods

run() click to toggle source
# File lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb, line 16
def run
  if need_to_run? || options[:force] == true
    Actions::CreateDirectory.new(File.join(examples_directory, 'support'), force: options[:force]).run
    Actions::CreateFile.new(:'example-test_case.rb', File.join(examples_directory, 'example_spec.rb'), test_case_data, force: options[:force], create_directories: true).run
    Actions::CreateFile.new(:'example-test_cases-gemfile.rb', File.join(examples_directory, 'Gemfile'), test_spec_helper_data, force: options[:force], create_directories: true).run
    Actions::CreateFile.new(:'example-spec_helper.rb', File.join(examples_directory, 'spec_helper.rb'), test_spec_helper_data, force: options[:force], create_directories: true).run
  else
    ProxyTester.ui_logger.warn "Directory with examples already exists at \"#{examples_directory}\" . Do not create it again!."
  end
end

Private Instance Methods

need_to_run?() click to toggle source
# File lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb, line 120
def need_to_run?
  !::File.exists? examples_directory
end
test_case_data() click to toggle source
# File lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb, line 90
def test_case_data
  Data.new(
    OpenStruct.new(
      example_directory: examples_directory,
      description: 'This is an example test case',
      proxies: [
        {
          host: 'proxy.example.org',
          port: 8080,
        },
        {
          host: 'proxy2.example.org',
          port: 3128,
        },
      ],
      urls: [
        {
          uri: 'http://www.example.org',
          content: 'Example Domain',
        },
        {
          uri: 'http://www.example.net',
          content: 'Example Domain',
        }
      ]
    )
  )

end
test_spec_helper_data() click to toggle source
# File lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb, line 29
def test_spec_helper_data
  Data.new(
    OpenStruct.new(
      libraries: [
        { 
          name: 'open-uri',
          require: 'open-uri',
          description: 'Easier use of urls in scripts',
          url: 'http://www.ruby-doc.org/stdlib-2.1.1/libdoc/open-uri/rdoc/OpenURI.html',
        },
      ],
      gems: [
        { 
          name: 'pry',
          description: 'REPL shell with completion to make writing specs easier',
          url: 'http://pryrepl.org/',
        },
        { 
          name: 'pry-debugger',
          description: 'Integration debugger into pry',
          require: false,
          url: 'https://github.com/nixme/pry-debugger',
        },
        { 
          name: 'pry-doc',
          description: 'Documentation for pry',
          require: false,
          url: 'http://pryrepl.org/',
        },
        { 
          name: 'debugger',
          description: 'The debugger for ruby. Please install the ruby gem "pry-debugger" for integration with pry.',
          url: 'http://pryrepl.org/',
        },
        { 
          name: 'debugger-completion',
          require: 'debugger/completion',
          description: 'Completion for debugger shell',
          url: 'https://github.com/cldwalker/debugger-completion',
        },
        { 
          name: 'nokogiri',
          description: 'HTML parser to make writing tests easier.',
          url: 'http://nokogiri.org/',
        },
        { 
          name: 'excon',
          description: 'HTTP library with proxy support',
          url: 'https://github.com/geemus/excon',
        },
        { 
          name: 'awesome_print',
          require: 'ap',
          description: 'Output data in repl shell',
          url: 'https://github.com/michaeldv/awesome_print',
        },
      ],
    )
  )
end