Improve readability of author_list spec.

This commit is contained in:
Glenn Y. Rolland 2014-09-25 10:02:08 +02:00
parent 2c28d6bc42
commit 1039218589
2 changed files with 23 additions and 20 deletions

View file

@ -1,52 +1,51 @@
require_relative 'spec_helper' require_relative 'spec_helper'
require 'minitest/spec'
require 'timecost' require 'timecost/author_list'
describe TimeCost::AuthorList do describe TimeCost::AuthorList do
let(:author_list) { TimeCost::AuthorList.new } let(:list) { TimeCost::AuthorList.new }
let(:author_first) { "foo@example.com" } let(:first) { "Foo <foo@example.com>" }
let(:author_second) { "bar@example.com" } let(:second) { "Bar <bar@example.com>" }
describe '.new' do describe '.new' do
it "can be created without arguments" do it "can be created without arguments" do
assert_instance_of TimeCost::AuthorList, author_list assert_instance_of TimeCost::AuthorList, list
end end
end end
describe '.add' do describe '.add' do
it "must accept adding authors" do it "must accept adding authors" do
assert_respond_to author_list, :add assert_respond_to list, :add
author_list.add "foo@example.com" list.add first
author_list.add "bar@example.com" list.add second
end end
it "must assign a different id to different authors" do it "must assign a different id to different authors" do
author_list.add "foo@example.com" list.add first
author_list.add "bar@example.com" list.add second
id_foo = author_list.parse "foo@example.com" id_foo = list.parse first
id_bar = author_list.parse "bar@example.com" id_bar = list.parse second
refute_equal id_foo, id_bar refute_equal id_foo, id_bar
end end
end end
describe '.alias' do describe '.alias' do
it "must accept aliases for authors" do it "must accept aliases for authors" do
assert_respond_to author_list, :alias assert_respond_to list, :alias
author_list.add author_first list.add first
author_list.alias author_first, author_second list.alias first, second
end end
it "must assign the same id to aliases authors" do it "must assign the same id to aliases authors" do
author_list.add author_first list.add first
author_list.alias author_first, author_second list.alias first, second
id_foo = author_list.parse author_first id_foo = list.parse first
id_bar = author_list.parse author_second id_bar = list.parse second
refute_equal id_foo, id_bar refute_equal id_foo, id_bar
end end
end end

View file

@ -1,9 +1,13 @@
#require 'mark' #require 'mark'
#
require 'minitest/unit' require 'minitest/unit'
require 'minitest/autorun' require 'minitest/autorun'
require 'minitest/spec'
require 'minitest/pride' require 'minitest/pride'
$LOAD_PATH.unshift('../lib')
#if __FILE__ == $0 #if __FILE__ == $0
# $LOAD_PATH.unshift('lib', 'spec') # $LOAD_PATH.unshift('lib', 'spec')
# Dir.glob('./spec/**/*_spec.rb') { |f| require f } # Dir.glob('./spec/**/*_spec.rb') { |f| require f }