From c969f8ecf483987a077abd68f007abf730a9cc09 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Fri, 21 Jul 2017 15:06:25 -0400 Subject: [PATCH] spec: add a test for making a new sprue --- lib/squib/commands/make_sprue.rb | 8 +++---- spec/commands/make_sprue_spec.rb | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 spec/commands/make_sprue_spec.rb diff --git a/lib/squib/commands/make_sprue.rb b/lib/squib/commands/make_sprue.rb index 61043c4..6fd69fb 100644 --- a/lib/squib/commands/make_sprue.rb +++ b/lib/squib/commands/make_sprue.rb @@ -15,9 +15,9 @@ module Squib class MakeSprue # :nodoc: # @api private - def process(args) + def process(args, input = $stdin, output = $stdout) # Get definitions from the user - @option = prompt + @option = prompt(input, output) @printable_edge_right = ( @option.sheet_width - @option.sheet_margin.right) @@ -38,9 +38,9 @@ module Squib private # Accept user input that defines the template. - def prompt + def prompt(input, output) option = TemplateOption.new - cli = HighLine.new + cli = HighLine.new(input, output) option.unit = cli.choose do |menu| menu.prompt = 'What measure unit should we use? ' diff --git a/spec/commands/make_sprue_spec.rb b/spec/commands/make_sprue_spec.rb new file mode 100644 index 0000000..94e7204 --- /dev/null +++ b/spec/commands/make_sprue_spec.rb @@ -0,0 +1,38 @@ +require 'highline' +require 'spec_helper' +require 'squib' + +describe Squib::Commands::MakeSprue do + + describe '#process' do + before(:each) do + @in = StringIO.new + @out = StringIO.new + @oldpwd = Dir.pwd + Dir.chdir(output_dir) + end + + after(:each) do + Dir.chdir @oldpwd + end + + it 'creates a custom sheet based on inputs' do + @in << + "1\n" << # Units inches + "4\n" << # Paper size A4 landscape + "0.135\n" << # Sheet margins + "3\n" << # Center align cards + "2.2\n" << # Card width + "3.5\n" << # Card height + "0\n" << # Gap + "1\n" << # Layout cards by row + "1\n" << # Generate crop lines + "foo.yml\n" # Output to foo.yml + @in.rewind + subject.process({}, @in, @out) + expect(@out.string).to match(/What measure/) + + end + end + +end