More unit testsgit pull
parent
e835228786
commit
4f575f9761
|
|
@ -89,7 +89,7 @@ module Squib
|
|||
Dir.mkdir opts[:dir]
|
||||
return opts
|
||||
else
|
||||
raise "#{opts[:dir]} does not exist!"
|
||||
raise "'#{opts[:dir]}' does not exist!"
|
||||
end
|
||||
end
|
||||
module_function :dirify
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|||
text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome",
|
||||
markup: true,
|
||||
x: 50, y: 1000,
|
||||
font: 'Arial 32'
|
||||
width: 750, height: 100,
|
||||
valign: :bottom,
|
||||
font: 'Arial 32', hint: :cyan
|
||||
|
||||
save prefix: 'text_', format: :png
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,48 +1,48 @@
|
|||
require 'spec_helper'
|
||||
require 'squib'
|
||||
|
||||
# describe Squib::Commands::New do
|
||||
describe Squib::Commands::New do
|
||||
|
||||
# describe "#process" do
|
||||
# before(:all) do
|
||||
# @old_stderr = $stderr
|
||||
# $stderr = StringIO.new
|
||||
# @oldpwd = Dir.pwd
|
||||
# Dir.chdir(File.expand_path('../../samples/_output', File.dirname(__FILE__)))
|
||||
# end
|
||||
describe "#process" do
|
||||
before(:all) do
|
||||
@old_stderr = $stderr
|
||||
$stderr = StringIO.new
|
||||
@oldpwd = Dir.pwd
|
||||
Dir.chdir(File.expand_path('../../samples/_output', File.dirname(__FILE__)))
|
||||
end
|
||||
|
||||
# before(:each) do
|
||||
# FileUtils.rm_rf('foo', secure: true)
|
||||
# @cmd = Squib::Commands::New.new
|
||||
# end
|
||||
before(:each) do
|
||||
FileUtils.rm_rf('foo', secure: true)
|
||||
@cmd = Squib::Commands::New.new
|
||||
end
|
||||
|
||||
# it "raises an error if no directory was specified" do
|
||||
# expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
|
||||
# end
|
||||
it "raises an error if no directory was specified" do
|
||||
expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
|
||||
end
|
||||
|
||||
# it "creates a new template on an fresh directory" do
|
||||
# @cmd.process(['foo'])
|
||||
# expect(File.exists?('foo/deck.rb')).to be true
|
||||
# end
|
||||
it "creates a new template on an fresh directory" do
|
||||
@cmd.process(['foo'])
|
||||
expect(File.exists?('foo/deck.rb')).to be true
|
||||
end
|
||||
|
||||
# it "creates a new template on an empty directory" do
|
||||
# Dir.mkdir('foo')
|
||||
# @cmd.process(['foo'])
|
||||
# expect(File.exists?('foo/deck.rb')).to be true
|
||||
# end
|
||||
it "creates a new template on an empty directory" do
|
||||
Dir.mkdir('foo')
|
||||
@cmd.process(['foo'])
|
||||
expect(File.exists?('foo/deck.rb')).to be true
|
||||
end
|
||||
|
||||
# it "does not create a new template on an empty " do
|
||||
# Dir.mkdir('foo')
|
||||
# File.new('foo/somefile.txt', 'w+')
|
||||
# @cmd.process(['foo'])
|
||||
# $stderr.rewind
|
||||
# expect($stderr.string.chomp).to end_with " exists and is not empty. Doing nothing and quitting."
|
||||
# end
|
||||
it "does not create a new template on an empty " do
|
||||
Dir.mkdir('foo')
|
||||
File.new('foo/somefile.txt', 'w+')
|
||||
@cmd.process(['foo'])
|
||||
$stderr.rewind
|
||||
expect($stderr.string.chomp).to end_with " exists and is not empty. Doing nothing and quitting."
|
||||
end
|
||||
|
||||
# after(:all) do
|
||||
# $stderr = @old_stderr
|
||||
# Dir.chdir(@oldpwd)
|
||||
# end
|
||||
# end
|
||||
after(:all) do
|
||||
$stderr = @old_stderr
|
||||
Dir.chdir(@oldpwd)
|
||||
end
|
||||
end
|
||||
|
||||
# end
|
||||
end
|
||||
|
|
@ -52,7 +52,29 @@ describe Squib::InputHelpers do
|
|||
it "defaults to a range of all cards if :all" do
|
||||
expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1})
|
||||
end
|
||||
end
|
||||
|
||||
context "#fileify" do
|
||||
it "should throw an error if the file doesn't exist" do
|
||||
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, false, true)}.to raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
||||
end
|
||||
|
||||
it "should expand singletons when asked" do
|
||||
expect(@deck.send(:fileify, {file: 'foo.txt'}, true, false)).to eq({file: ['foo.txt', 'foo.txt']})
|
||||
end
|
||||
end
|
||||
|
||||
context "#dir" do
|
||||
it "should raise an error if the directory does not exist" do
|
||||
expect{@deck.send(:dirify, {dir: 'nonexist'}, false)}.to raise_error(RuntimeError,"'nonexist' does not exist!")
|
||||
end
|
||||
end
|
||||
|
||||
context "#colorify" do
|
||||
it "should parse if nillable" do
|
||||
color = @deck.send(:colorify, {color: '#fff'}, true)[:color]
|
||||
expect(color.to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in New Issue