spec/ rubocopied
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
require "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe CustomOptionParser do
|
||||
|
||||
let(:parser) { CustomOptionParser.new }
|
||||
|
||||
describe "#new" do
|
||||
describe '#new' do
|
||||
|
||||
end
|
||||
|
||||
describe "::option_to_symbol" do
|
||||
describe '::option_to_symbol' do
|
||||
after :each do
|
||||
if @exception
|
||||
expect { CustomOptionParser::option_to_symbol(@option) }.to raise_error(@exception)
|
||||
@@ -17,135 +19,135 @@ describe CustomOptionParser do
|
||||
end
|
||||
end
|
||||
|
||||
context "without REQUIRED or OPTIONAL arguments" do
|
||||
context "with short option" do
|
||||
it "should return :test" do
|
||||
@option = ["-t", "--test", "Testing"]
|
||||
context 'without REQUIRED or OPTIONAL arguments' do
|
||||
context 'with short option' do
|
||||
it 'should return :test' do
|
||||
@option = ['-t', '--test', 'Testing']
|
||||
@expected = :test
|
||||
end
|
||||
|
||||
it "should :its_a_long_option" do
|
||||
@option = ["-l", "--its-a-long-option", "Testing '-' replacement"]
|
||||
it 'should :its_a_long_option' do
|
||||
@option = ['-l', '--its-a-long-option', "Testing '-' replacement"]
|
||||
@expected = :its_a_long_option
|
||||
end
|
||||
end
|
||||
|
||||
context "without short option" do
|
||||
it "should return :long" do
|
||||
@option = ["--long", "The method should find the option name ('long')"]
|
||||
context 'without short option' do
|
||||
it 'should return :long' do
|
||||
@option = ['--long', "The method should find the option name ('long')"]
|
||||
@expected = :long
|
||||
end
|
||||
|
||||
it "should return :long_option" do
|
||||
@option = ["--long-option", "No short !"]
|
||||
it 'should return :long_option' do
|
||||
@option = ['--long-option', 'No short !']
|
||||
@expected = :long_option
|
||||
end
|
||||
end
|
||||
|
||||
context "without long option" do
|
||||
it "should raise an arror" do
|
||||
@option = ["-v", "The long option is missing there"]
|
||||
@exception = "Could not find the option name for [\"-v\", \"The long option is missing there\"]"
|
||||
context 'without long option' do
|
||||
it 'should raise an arror' do
|
||||
@option = ['-v', 'The long option is missing there']
|
||||
@exception = 'Could not find the option name for ["-v", "The long option is missing there"]'
|
||||
end
|
||||
|
||||
it "should raise an error" do
|
||||
@option = ["The long option is missing there"]
|
||||
@exception = "Could not find the option name for [\"The long option is missing there\"]"
|
||||
it 'should raise an error' do
|
||||
@option = ['The long option is missing there']
|
||||
@exception = 'Could not find the option name for ["The long option is missing there"]'
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple long option names (like alias)" do
|
||||
it "should return :check_long and not :cl" do
|
||||
@option = ["--check-long", "--cl"]
|
||||
context 'with multiple long option names (like alias)' do
|
||||
it 'should return :check_long and not :cl' do
|
||||
@option = ['--check-long', '--cl']
|
||||
@expected = :check_long
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with REQUIRED or OPTIONAL arguments" do
|
||||
it "should removed the OPTIONAL argument" do
|
||||
@option = ["-p", "--page [PAGE_NUMBER]"]
|
||||
context 'with REQUIRED or OPTIONAL arguments' do
|
||||
it 'should removed the OPTIONAL argument' do
|
||||
@option = ['-p', '--page [PAGE_NUMBER]']
|
||||
@expected = :page
|
||||
end
|
||||
|
||||
it "should removed the REQUIRED argument" do
|
||||
@option = ["--url TARGET_URL"]
|
||||
it 'should removed the REQUIRED argument' do
|
||||
@option = ['--url TARGET_URL']
|
||||
@expected = :url
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#add_option" do
|
||||
context "exception throwing if" do
|
||||
describe '#add_option' do
|
||||
context 'exception throwing if' do
|
||||
after :each do
|
||||
expect { parser.add_option(@option) }.to raise_error(@exception)
|
||||
end
|
||||
|
||||
it "argument passed is not an Array" do
|
||||
@option = "a simple String"
|
||||
it 'argument passed is not an Array' do
|
||||
@option = 'a simple String'
|
||||
@exception = "The option must be an array, String supplied : 'a simple String'"
|
||||
end
|
||||
|
||||
it "option name is already used" do
|
||||
@option = ["-v", "--verbose", "Verbose mode"]
|
||||
it 'option name is already used' do
|
||||
@option = ['-v', '--verbose', 'Verbose mode']
|
||||
parser.add_option(@option)
|
||||
@exception = "The option verbose is already used !"
|
||||
@exception = 'The option verbose is already used !'
|
||||
end
|
||||
end
|
||||
|
||||
it "should have had 2 symbols (:verbose, :url) to @symbols_used" do
|
||||
parser.add_option(["-v", "--verbose"])
|
||||
parser.add_option(["--url TARGET_URL"])
|
||||
it 'should have had 2 symbols (:verbose, :url) to @symbols_used' do
|
||||
parser.add_option(['-v', '--verbose'])
|
||||
parser.add_option(['--url TARGET_URL'])
|
||||
|
||||
parser.symbols_used.sort.should === [:url, :verbose]
|
||||
end
|
||||
|
||||
context "parsing" do
|
||||
context 'parsing' do
|
||||
before :each do
|
||||
parser.add_option(["-u", "--url TARGET_URL", "Set the target url"])
|
||||
parser.add_option(['-u', '--url TARGET_URL', 'Set the target url'])
|
||||
end
|
||||
|
||||
it "should raise an error if an unknown option is supplied" do
|
||||
expect { parser.parse!(["--verbose"]) }.to raise_error(OptionParser::InvalidOption)
|
||||
it 'should raise an error if an unknown option is supplied' do
|
||||
expect { parser.parse!(['--verbose']) }.to raise_error(OptionParser::InvalidOption)
|
||||
end
|
||||
|
||||
it "should raise an error if an option require an argument which is not supplied" do
|
||||
expect { parser.parse!(["--url"]) }.to raise_error(OptionParser::MissingArgument)
|
||||
it 'should raise an error if an option require an argument which is not supplied' do
|
||||
expect { parser.parse!(['--url']) }.to raise_error(OptionParser::MissingArgument)
|
||||
end
|
||||
|
||||
it "should retrieve the correct argument" do
|
||||
parser.parse!(["-u", "iam_the_target"])
|
||||
parser.results.should === { :url => "iam_the_target" }
|
||||
it 'should retrieve the correct argument' do
|
||||
parser.parse!(['-u', 'iam_the_target'])
|
||||
parser.results.should === { url: 'iam_the_target' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add" do
|
||||
it "should raise an error if the argument is not an Array or Array(Array)" do
|
||||
expect { parser.add("Hello") }.to raise_error("Options must be at least an Array, or an Array(Array). String supplied")
|
||||
describe '#add' do
|
||||
it 'should raise an error if the argument is not an Array or Array(Array)' do
|
||||
expect { parser.add('Hello') }.to raise_error('Options must be at least an Array, or an Array(Array). String supplied')
|
||||
end
|
||||
|
||||
before :each do
|
||||
parser.add(["-u", "--url TARGET_URL"])
|
||||
parser.add(['-u', '--url TARGET_URL'])
|
||||
end
|
||||
|
||||
context "single option" do
|
||||
it "should add the :url option, and retrieve the correct argument" do
|
||||
parser.symbols_used.should === [ :url ]
|
||||
parser.results(["-u", "target.com"]).should === { :url => "target.com" }
|
||||
context 'single option' do
|
||||
it 'should add the :url option, and retrieve the correct argument' do
|
||||
parser.symbols_used.should === [:url]
|
||||
parser.results(['-u', 'target.com']).should === { url: 'target.com' }
|
||||
end
|
||||
end
|
||||
|
||||
context "multiple options" do
|
||||
it "should add 2 options, and retrieve the correct arguments" do
|
||||
context 'multiple options' do
|
||||
it 'should add 2 options, and retrieve the correct arguments' do
|
||||
parser.add([
|
||||
["-v", "--verbose"],
|
||||
["--test [TEST_NUMBER]"]
|
||||
['-v', '--verbose'],
|
||||
['--test [TEST_NUMBER]']
|
||||
])
|
||||
|
||||
parser.symbols_used.sort.should === [:test, :url, :verbose]
|
||||
parser.results(["-u", "wp.com", "-v", "--test"]).should === { :test => nil, :url => "wp.com", :verbose => true }
|
||||
parser.results(['-u', 'wp.com', '-v', '--test']).should === { test: nil, url: 'wp.com', verbose: true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Plugin do
|
||||
subject(:plugin) { Plugin.new }
|
||||
|
||||
describe "#new" do
|
||||
context "with some infos" do
|
||||
describe '#new' do
|
||||
context 'with some infos' do
|
||||
subject(:plugin) { Plugin.new(infos) }
|
||||
let(:infos) { {:author => "John"} }
|
||||
let(:infos) { { author: 'John' } }
|
||||
|
||||
its(:author) { should === infos[:author] }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#run" do
|
||||
it "should raise a NotImplementedError" do
|
||||
describe '#run' do
|
||||
it 'should raise a NotImplementedError' do
|
||||
expect { plugin.run }.to raise_error(NotImplementedError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#register_options" do
|
||||
describe '#register_options' do
|
||||
after :each do
|
||||
if @exception
|
||||
expect { plugin.register_options(*@options) }.to raise_error(@exception)
|
||||
@@ -28,16 +30,22 @@ describe Plugin do
|
||||
end
|
||||
end
|
||||
|
||||
context "when an option is not an Array" do
|
||||
it "should raise an error" do
|
||||
@options = [["-v", "--verbose", "It's a valid option"], "Not a valid one"]
|
||||
@exception = "Each option must be an array, String supplied"
|
||||
context 'when an option is not an Array' do
|
||||
it 'should raise an error' do
|
||||
@options = [
|
||||
['-v', '--verbose', 'It\'s a valid option'],
|
||||
'Not a valid one'
|
||||
]
|
||||
@exception = 'Each option must be an array, String supplied'
|
||||
end
|
||||
end
|
||||
|
||||
context "when options are Arrays" do
|
||||
it "should register the options" do
|
||||
@options = [["-v", "--verbose", "Verbose mode"], ["-u", "--url TARGET_URL"]]
|
||||
context 'when options are Arrays' do
|
||||
it 'should register the options' do
|
||||
@options = [
|
||||
['-v', '--verbose', 'Verbose mode'],
|
||||
['-u', '--url TARGET_URL']
|
||||
]
|
||||
@expected = *@options
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
require "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
class TestPlugin < Plugin
|
||||
def initialize
|
||||
register_options(["-u", "--url"])
|
||||
register_options(['-u', '--url'])
|
||||
end
|
||||
end
|
||||
|
||||
class AnotherPlugin < Plugin
|
||||
def initialize
|
||||
super(:author => "John")
|
||||
super(author: 'John')
|
||||
# No Options
|
||||
end
|
||||
end
|
||||
@@ -19,28 +21,28 @@ describe Plugins do
|
||||
let(:test_plugin) { TestPlugin.new }
|
||||
let(:another_plugin) { AnotherPlugin.new }
|
||||
|
||||
describe "#new" do
|
||||
context "without argument" do
|
||||
describe '#new' do
|
||||
context 'without argument' do
|
||||
its(:option_parser) { should be_a CustomOptionParser }
|
||||
|
||||
it "should be an Array" do
|
||||
it 'should be an Array' do
|
||||
plugins.should be_an Array
|
||||
end
|
||||
end
|
||||
|
||||
context "with an option_parser argument" do
|
||||
subject(:plugin) { Plugins.new(CustomOptionParser.new("the banner")) }
|
||||
context 'with an option_parser argument' do
|
||||
subject(:plugin) { Plugins.new(CustomOptionParser.new('the banner')) }
|
||||
|
||||
its(:option_parser) { should be_a CustomOptionParser }
|
||||
its("option_parser.banner") { should === "the banner" }
|
||||
its('option_parser.banner') { should === 'the banner' }
|
||||
|
||||
it "should raise an eror if the parser is not an instance of CustomOptionParser" do
|
||||
expect { Plugins.new(OptionParser.new) }.to raise_error("The parser must be an instance of CustomOptionParser, OptionParser supplied")
|
||||
it 'should raise an eror if the parser is not an instance of CustomOptionParser' do
|
||||
expect { Plugins.new(OptionParser.new) }.to raise_error('The parser must be an instance of CustomOptionParser, OptionParser supplied')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#register_plugin" do
|
||||
describe '#register_plugin' do
|
||||
after :each do
|
||||
if @exception
|
||||
expect { plugins.register_plugin(@plugin) }.to raise_error(@exception)
|
||||
@@ -51,27 +53,27 @@ describe Plugins do
|
||||
end
|
||||
end
|
||||
|
||||
context "when the argument supplied is not an instance of Plugin" do
|
||||
it "should raise an error" do
|
||||
@plugin = "I'am a String"
|
||||
@exception = "The argument must be an instance of Plugin, String supplied"
|
||||
context 'when the argument supplied is not an instance of Plugin' do
|
||||
it 'should raise an error' do
|
||||
@plugin = "I'am a String"
|
||||
@exception = 'The argument must be an instance of Plugin, String supplied'
|
||||
end
|
||||
end
|
||||
|
||||
it "should register the plugin" do
|
||||
it 'should register the plugin' do
|
||||
@plugin = TestPlugin.new
|
||||
@expected = [@plugin]
|
||||
end
|
||||
|
||||
it "should register 2 plugins (the order is important)" do
|
||||
it 'should register 2 plugins (the order is important)' do
|
||||
plugins.register_plugin(test_plugin)
|
||||
|
||||
@plugin = another_plugin
|
||||
@plugin = another_plugin
|
||||
@expected = [test_plugin, @plugin]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#register" do
|
||||
describe '#register' do
|
||||
after :each do
|
||||
plugins.register(*@plugins_to_register)
|
||||
|
||||
@@ -83,11 +85,11 @@ describe Plugins do
|
||||
plugins.should === @plugins_to_register
|
||||
end
|
||||
|
||||
it "should register 1 plugin" do
|
||||
it 'should register 1 plugin' do
|
||||
@plugins_to_register = [test_plugin]
|
||||
end
|
||||
|
||||
it "should register 2 plugins" do
|
||||
it 'should register 2 plugins' do
|
||||
@plugins_to_register = [another_plugin, test_plugin]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user