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

View file

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