Skip to content

Commit

Permalink
Change to extract test helpers for wrapping options dsl in a class
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed May 4, 2020
1 parent ba64317 commit ef58080
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def new_parameter(type, name, **settings)
param_class = Object.const_get("TTY::Option::Parameter::#{type.capitalize}")
param_class.new(name, **settings)
end

def command(name = "Command", parent = nil, &block)
stub_const(name, parent ? Class.new(parent) : Class.new)
klass = Object.const_get(name)
klass.send :include, TTY::Option
klass.class_eval(&block) if block
klass
end

def new_command(&block)
command(&block).new
end
end

RSpec.configure do |config|
Expand Down
11 changes: 0 additions & 11 deletions spec/unit/help_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# frozen_string_literal: true

RSpec.describe TTY::Option::Formatter do
def command(&block)
stub_const("Command", Class.new)
Command.send :include, TTY::Option
Command.class_eval(&block)
Command
end

def new_command(&block)
command(&block).new
end

context "Usage header & footer" do
it "includes header and footer in help display" do
cmd = new_command do
Expand Down
11 changes: 0 additions & 11 deletions spec/unit/parse_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# frozen_string_literal: true

RSpec.describe TTY::Option do
def command(&block)
stub_const("Command", Class.new)
Command.send :include, TTY::Option
Command.class_eval(&block)
Command
end

def new_command(&block)
command(&block).new
end

it "doesn't allow to register same name parameter" do
expect {
command do
Expand Down

0 comments on commit ef58080

Please sign in to comment.