Skip to content

Commit d4ba7e0

Browse files
committed
switch to rspec
1 parent e7c9f7d commit d4ba7e0

14 files changed

+329
-384
lines changed

Gemfile

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
source "http://rubygems.org"
2-
# Add dependencies required to use your gem here.
3-
# Example:
4-
# gem "activesupport", ">= 2.3.5"
52

6-
# Add dependencies to develop your gem here.
7-
# Include everything needed to run rake, tests, features, etc.
8-
group :development do
9-
gem "shoulda", ">= 0"
10-
gem "bundler", "~> 1.0.0"
11-
gem "jeweler", "~> 1.5.1"
12-
gem "rcov", ">= 0"
13-
end
3+
# Specify your gem's dependencies in test.gemspec
4+
gemspec

Rakefile

+30-34
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,41 @@ rescue Bundler::BundlerError => e
88
exit e.status_code
99
end
1010
require 'rake'
11+
require 'rspec'
12+
require 'rspec/core/rake_task'
1113

12-
require 'jeweler'
13-
Jeweler::Tasks.new do |gem|
14-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15-
gem.name = "anvl"
16-
gem.homepage = "http://github.com/cbeer/anvl"
17-
gem.license = "MIT"
18-
gem.summary = %Q{Ruby implementation of A Name-Value Language (ANVL)}
19-
gem.email = "chris@cbeer.info"
20-
gem.authors = ["Chris Beer"]
21-
# Include your dependencies below. Runtime dependencies are required when using your gem,
22-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
24-
# gem.add_development_dependency 'rspec', '> 1.2.3'
14+
RSpec::Core::RakeTask.new() do |t|
15+
t.pattern = "./spec/*_spec.rb" # don't need this, it's default.
16+
t.rcov = true
17+
t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
2518
end
26-
Jeweler::RubygemsDotOrgTasks.new
2719

28-
require 'rake/testtask'
29-
Rake::TestTask.new(:test) do |test|
30-
test.libs << 'lib' << 'test'
31-
test.pattern = 'test/**/test_*.rb'
32-
test.verbose = true
20+
desc "Generate code coverage"
21+
RSpec::Core::RakeTask.new(:rcov) do |t|
22+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
23+
t.rcov = true
24+
t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
3325
end
3426

35-
require 'rcov/rcovtask'
36-
Rcov::RcovTask.new do |test|
37-
test.libs << 'test'
38-
test.pattern = 'test/**/test_*.rb'
39-
test.verbose = true
40-
end
41-
42-
task :default => :test
27+
task :default => :rcov
28+
task :hudson => [:rcov, :doc]
4329

44-
require 'rake/rdoctask'
45-
Rake::RDocTask.new do |rdoc|
46-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
30+
# Use yard to build docs
31+
begin
32+
require 'yard'
33+
require 'yard/rake/yardoc_task'
34+
project_root = File.expand_path(File.dirname(__FILE__))
35+
doc_destination = File.join(project_root, 'doc')
4736

48-
rdoc.rdoc_dir = 'rdoc'
49-
rdoc.title = "anvl #{version}"
50-
rdoc.rdoc_files.include('README*')
51-
rdoc.rdoc_files.include('lib/**/*.rb')
37+
YARD::Rake::YardocTask.new(:doc) do |yt|
38+
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
39+
[ File.join(project_root, 'README.textile') ]
40+
yt.options = ['--output-dir', doc_destination, '--readme', 'README.rdoc']
41+
end
42+
rescue LoadError
43+
desc "Generate YARD Documentation"
44+
task :doc do
45+
abort "Please install the YARD gem to generate rdoc."
46+
end
5247
end
48+

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.1
1+
0.3.0

anvl.gemspec

+12-54
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,28 @@
1-
# Generated by jeweler
2-
# DO NOT EDIT THIS FILE DIRECTLY
3-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
41
# -*- encoding: utf-8 -*-
52

63
Gem::Specification.new do |s|
74
s.name = %q{anvl}
8-
s.version = "0.2.1"
5+
s.version = "0.3.0"
96

107
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
118
s.authors = ["Chris Beer"]
12-
s.date = %q{2010-12-15}
9+
s.date = %q{2011-06-12}
1310
s.email = %q{chris@cbeer.info}
1411
s.extra_rdoc_files = [
1512
"LICENSE.txt",
1613
"README.rdoc"
1714
]
18-
s.files = [
19-
".document",
20-
"Gemfile",
21-
"Gemfile.lock",
22-
"LICENSE.txt",
23-
"README.rdoc",
24-
"Rakefile",
25-
"VERSION",
26-
"anvl.gemspec",
27-
"lib/anvl.rb",
28-
"lib/anvl/document.rb",
29-
"lib/anvl/element.rb",
30-
"lib/anvl/erc.rb",
31-
"test/helper.rb",
32-
"test/test_anvl.rb",
33-
"test/test_element.rb",
34-
"test/test_erc.rb"
35-
]
36-
s.homepage = %q{http://github.com/cbeer/anvl}
37-
s.licenses = ["MIT"]
38-
s.require_paths = ["lib"]
39-
s.rubygems_version = %q{1.3.7}
40-
s.summary = %q{Ruby implementation of A Name-Value Language (ANVL)}
41-
s.test_files = [
42-
"test/helper.rb",
43-
"test/test_anvl.rb",
44-
"test/test_element.rb",
45-
"test/test_erc.rb"
46-
]
4715

48-
if s.respond_to? :specification_version then
49-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50-
s.specification_version = 3
16+
s.files = `git ls-files`.split("\n")
17+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19+
s.require_paths = ["lib"]
5120

52-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53-
s.add_development_dependency(%q<shoulda>, [">= 0"])
54-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
56-
s.add_development_dependency(%q<rcov>, [">= 0"])
57-
else
58-
s.add_dependency(%q<shoulda>, [">= 0"])
59-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61-
s.add_dependency(%q<rcov>, [">= 0"])
62-
end
63-
else
64-
s.add_dependency(%q<shoulda>, [">= 0"])
65-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67-
s.add_dependency(%q<rcov>, [">= 0"])
68-
end
21+
# Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
22+
s.add_development_dependency "rake"
23+
s.add_development_dependency "bundler"
24+
s.add_development_dependency "rspec"
25+
s.add_development_dependency 'rcov'
26+
s.add_development_dependency 'yard'
6927
end
7028

lib/anvl/version.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ANVL
2+
unless ANVL.const_defined? :VERSION
3+
def self.version
4+
@version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
5+
end
6+
7+
VERSION = self.version
8+
end
9+
end
10+

spec/.anvl_spec.rb.swp

12 KB
Binary file not shown.

spec/anvl_spec.rb

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "ANVL" do
4+
describe "parsing tests" do
5+
it "should parse empty files" do
6+
anvl = ANVL.parse('')
7+
anvl.entries.should have(0).items
8+
end
9+
10+
it "should ignore comment lines" do
11+
anvl = ANVL.parse("#")
12+
anvl.entries.should have(0).items
13+
end
14+
15+
it "should handle multiple values" do
16+
anvl = ANVL.parse "entry:
17+
a: 1
18+
a: 2"
19+
20+
anvl[:a].should == ["1","2"]
21+
end
22+
23+
it "should suport string or key access" do
24+
str = 'erc:
25+
who: Lederberg, Joshua
26+
what: Studies of Human Families for Genetic Linkage
27+
when: 1974
28+
where: http://profiles.nlm.nih.gov/BB/AA/TT/tt.pdf
29+
note: This is an arbitrary note inside a
30+
small descriptive record.'
31+
anvl = ANVL::Document.parse str
32+
anvl['who'].should == anvl[:who]
33+
34+
35+
end
36+
37+
38+
it "should parse a complete document" do
39+
anvl = ANVL.parse <<-eos
40+
entry:
41+
# first draft
42+
who: Gilbert, W.S. | Sullivan, Arthur
43+
what: The Yeomen of
44+
the Guard
45+
when/created: 1888
46+
eos
47+
anvl[:entry].should == ""
48+
anvl[:who].should == "Gilbert, W.S. | Sullivan, Arthur"
49+
anvl[:what].should == "The Yeomen of the Guard"
50+
anvl[:"when/created"].should == "1888"
51+
52+
end
53+
end
54+
55+
describe "serializing test" do
56+
it "should output an empty document" do
57+
str = ANVL.to_anvl({})
58+
str.should == ""
59+
end
60+
61+
it "should handle new lines by indenting appropriately" do
62+
str = ANVL.to_anvl({:with_newline => "abc\n123"})
63+
str.should == "with_newline: abc\n 123"
64+
end
65+
66+
it "should support label aliases" do
67+
str = ANVL.to_anvl(:a => {:display_label => 'A', :value => '123'})
68+
str.should match(/A: 123/)
69+
end
70+
71+
it "should serialize a complete document" do
72+
str = ANVL.to_anvl({:entry => [""], :who => ['Gilbert, W.S. | Sullivan, Arthur'], :what => ["The Yeomen of the Guard"], :"when/created" => [1888]})
73+
74+
arr = str.split("\n")
75+
76+
arr.should include("who: Gilbert, W.S. | Sullivan, Arthur", "what: The Yeomen of the Guard", "when/created: 1888")
77+
78+
end
79+
80+
it "should support iteratively building a document" do
81+
anvl = ANVL::Document.new
82+
anvl[:a].should == []
83+
84+
anvl[:a] = 'a'
85+
anvl.to_h.should == {:a => 'a'}
86+
87+
anvl[:a] = ['a', 'b']
88+
anvl.to_h.should == {:a => ['a', 'b']}
89+
90+
anvl.store :a, 'c', true
91+
anvl.to_h.should == {:a => ['a', 'b', 'c']}
92+
93+
anvl << { :a => 'd' }
94+
anvl.to_h.should == {:a => ['a', 'b', 'c', 'd']}
95+
96+
anvl[:b]
97+
anvl.to_h[:b].should be_nil
98+
99+
anvl << { :c => 1 }
100+
anvl[:c].should == "1"
101+
102+
anvl << { :c => 2 }
103+
anvl[:c].should == ["1", "2"]
104+
105+
arr = anvl.to_s.split("\n")
106+
arr.should include("a: a", "a: b", "a: c", "a: d", "c: 1", "c: 2")
107+
end
108+
end
109+
end
110+

spec/element_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
require 'anvl/erc'
3+
4+
describe "ERC element" do
5+
it "should handle basic mapping" do
6+
h = ANVL::Erc::Element.new :label => 'abc', :value => '123'
7+
h.to_s.should == "123"
8+
h.to_anvl.should == "abc: 123"
9+
end
10+
11+
it "should support an initial comment to record natural word order" do
12+
h = ANVL::Erc::Element.new :label => 'abc', :value => ', van Gogh, Vincent'
13+
h.to_s.should == "Vincent van Gogh"
14+
h.to_anvl.should == "abc:, van Gogh, Vincent"
15+
16+
h = ANVL::Erc::Element.new :label => 'abc', :value => ', Howell, III, PhD, 1922-1987, Thurston'
17+
h.to_s.should == "Thurston Howell, III, PhD, 1922-1987"
18+
h.to_anvl.should == "abc:, Howell, III, PhD, 1922-1987, Thurston"
19+
20+
h = ANVL::Erc::Element.new :label => 'abc', :value => ', McCartney, Paul, Sir,'
21+
h.to_s.should == "Sir Paul McCartney"
22+
h.to_anvl.should == "abc:, McCartney, Paul, Sir,"
23+
end
24+
end

0 commit comments

Comments
 (0)