Skip to content
Browse files

More refactoring for Rails 3 & Ruby 1.9.2

  • Loading branch information...
1 parent 0bc6869 commit d4c42aaf28cbcbf041aac52aefec6ab6c8f8ea6f @pboling committed Jun 14, 2011
Showing with 370 additions and 249 deletions.
  1. +5 −0 .document
  2. +53 −7 .gitignore
  3. +4 −0 CHANGELOG → CHANGELOG.txt
  4. +5 −3 Gemfile
  5. 0 LICENSE → LICENSE.txt
  6. +26 −18 README.rdoc
  7. +18 −8 Rakefile
  8. +20 −7 csv_pirate.gemspec
  9. +1 −1 lib/csv_pirate/version.rb
  10. +19 −205 spec/csv_pirate_spec.rb
  11. +219 −0 spec/the_capn_spec.rb
View
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
View
60 .gitignore
@@ -1,15 +1,61 @@
-*.gem
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
.bundle
Gemfile.lock
-pkg/*
-*.sw?
+
+# jeweler generated
+pkg
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
.DS_Store
-coverage
-coverage/*
-doc
-doc/*
+
+# For IDEs:
+#
.project
.project/*
.idea
.idea/*
+
+# For TextMate
+#*.tmproj
+#tmtags
+
+# For emacs:
+#*~
+#\#*
+#.\#*
+
+# For vim:
+#*.swp
+
+# For redcar:
+#.redcar
+
+# For rubinius:
+#*.rbc
+
+# Other
+*.gem
+*.sw?
spec/csv/*
View
4 CHANGELOG → CHANGELOG.txt
@@ -1,3 +1,7 @@
+Version 5.0.0 2011-06-14
+- Added .txt extension to CHANGELOG and LINCENSE
+- Improved dependency declarations in Gemfile (removed from Rakefile/gemspec)
+
Version 5.0.0 2011-06-13
- Ruby 1.9.2p136 compatible
- Rails 3.0.x compatible
View
8 Gemfile
@@ -1,12 +1,14 @@
source :rubygems
-gemspec
-
#FasterCSV became the built-in CSV library in Ruby 1.9, so is only required if using Ruby 1.8
if RUBY_VERSION =~ /^1\.8\.\d{1}$/
gem 'fastercsv', '~> 1.5'
end
-group :test do
+group :development do
gem 'rspec', '~> 2.6'
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.6.2"
+ gem "rcov", ">= 0"
end
View
0 LICENSE → LICENSE.txt
File renamed without changes.
View
44 README.rdoc
@@ -45,15 +45,6 @@ Avast! Here be pirates! To brush up on pirate coding naming conventions:
http://www.privateerdragons.com/pirate_dictionary.html
-== New for version 4.x... Importing to DB or Ruby objects in memory from CSV
-
-Importing abilities are now here! You can dump data to CSV, copy the CSV to wherever, and then import the data in the CSV. Works very well with ActiveRecord.
-
-See the weigh_anchor method, added to models with has_csv_pirate_ship defined, for dumping.
-See the raise_anchor method, added to models with has_csv_pirate_ship defined, for importing.
-See the to_memory method to convert the data in a csv or CsvPirate instance object back into Ruby class instances
-with as many attributes as possible set equal to the data from the CSV.
-
== On The Web
Source:
@@ -65,10 +56,6 @@ Release Announcement:
== Install as a RubyGem
-Gemcutter is the hot new gem host, and you can use it like this (see http://gemcutter.org):
-
- [sudo] gem install gemcutter
- [sudo] gem tumble # makes gemcutter gem source first in line
[sudo] gem install csv_pirate
Gem Using Git building from source:
@@ -78,7 +65,7 @@ Gem Using Git building from source:
git clone git://github.com/pboling/csv_pirate.git
cd csv_pirate
gem build csv_pirate.gemspec
- sudo gem install csv_pirate-3.4.4.gem # (Or whatever version gets built)
+ sudo gem install csv_pirate-5.0.1.gem # (Or whatever version gets built)
Then in your environment.rb (if you are just going to use it from the console, you can require it as needed there, and skip the config.gem):
@@ -117,6 +104,15 @@ What's the simplest thing that will work?
MyClass.walk_the_plank # creates the csv, and returns contents of the exported data (that was written into the csv) (as a string)
MyClass.land_ho # Does Not create the csv, sets up the CsvPirate instance. You can manipulate it and then call .hoist_mainstay on it to create the csv
+== Importing to DB or Ruby objects in memory from CSV
+
+Importing abilities are now here! You can dump data to CSV, copy the CSV to wherever, and then import the data in the CSV. Works very well with ActiveRecord.
+
+See the weigh_anchor method, added to models with has_csv_pirate_ship defined, for dumping.
+See the raise_anchor method, added to models with has_csv_pirate_ship defined, for importing.
+See the to_memory method to convert the data in a csv or CsvPirate instance object back into Ruby class instances
+with as many attributes as possible set equal to the data from the CSV.
+
== Usage without ActiveRecord
[ See Spec Tests for more Examples! ]
@@ -444,12 +440,24 @@ if you need to export the id field.
Micrsoft... I loathe you.
http://www.bradino.com/misc/sylk-file-format-is-not-valid/
+== Contributing to CsvPirate
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests, rspec preferred, for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or change log. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+
== Thanks
-Thanks go to
-9thBit LLC (http://www.9thBit.net)
-Sagebit LLC (http://www.sagebit.com) - Sagebit has been very supportive of my open source efforts, thanks Ben!
-TimePerks LLC (http://www.timeperks.com) - Many useful enhancements were requested and paid for by TimePerks
+Thanks go to:
+
+* 9thBit LLC (http://www.9thBit.net) - Peter Boling, author of CsvPirate, runs the joint.
+* Sagebit LLC (http://www.sagebit.com) - Sagebit has been very supportive of my open source efforts, thanks Ben!
+* TimePerks LLC (http://www.timeperks.com) - Many useful enhancements were requested and paid for by TimePerks
----------------------------------------------------------------------------------
Author: Peter Boling, peter.boling at gmail dot com
View
26 Rakefile
@@ -1,6 +1,14 @@
-require 'bundler'
-Bundler::GemHelper.install_tasks
+# encoding: utf-8
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
require 'rake'
begin
@@ -23,26 +31,28 @@ It works better if you are wearing a tricorne!}
"lib/csv_pirate/version.rb",
"spec/csv_pirate_spec.rb",
"spec/pirate_ship_spec.rb",
+ "spec/the_capn_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"spec/spec_helpers/glowing_gas_ball.rb",
"spec/spec_helpers/star.rb",
"Rakefile",
"Gemfile",
- "LICENSE",
- "CHANGELOG",
+ "LICENSE.txt",
+ "CHANGELOG.txt",
"VERSION.yml"]
end
- Jeweler::GemcutterTasks.new
+ Jeweler::RubygemsDotOrgTasks.new
rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
end
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'csv_pirate'
- rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.title = "csv_pirate2 #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
View
27 csv_pirate.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{csv_pirate}
- s.version = "5.0.0"
+ s.version = "5.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Peter Boling"]
@@ -14,13 +14,13 @@ Gem::Specification.new do |s|
It works better if you are wearing a tricorne!}
s.email = %q{peter.boling@gmail.com}
s.extra_rdoc_files = [
- "LICENSE",
+ "LICENSE.txt",
"README.rdoc"
]
s.files = [
- "CHANGELOG",
+ "CHANGELOG.txt",
"Gemfile",
- "LICENSE",
+ "LICENSE.txt",
"README.rdoc",
"Rakefile",
"VERSION.yml",
@@ -36,6 +36,7 @@ It works better if you are wearing a tricorne!}
"spec/spec_helper.rb",
"spec/spec_helpers/glowing_gas_ball.rb",
"spec/spec_helpers/star.rb",
+ "spec/the_capn_spec.rb",
"uninstall.rb"
]
s.homepage = %q{http://github.com/pboling/csv_pirate}
@@ -47,12 +48,24 @@ It works better if you are wearing a tricorne!}
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<csv_pirate>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.6"])
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
+ s.add_development_dependency(%q<rcov>, [">= 0"])
else
- s.add_dependency(%q<csv_pirate>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.6"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
+ s.add_dependency(%q<rcov>, [">= 0"])
end
else
- s.add_dependency(%q<csv_pirate>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.6"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
+ s.add_dependency(%q<rcov>, [">= 0"])
end
end
View
2 lib/csv_pirate/version.rb
@@ -1,6 +1,6 @@
module CsvPirate
- @@conf = YAML::load( File.read('VERSION.yml') )
+ @@conf = YAML::load( File.read( File.absolute_path('VERSION.yml') ) )
MAJOR = @@conf[:major]
MINOR = @@conf[:minor]
View
224 spec/csv_pirate_spec.rb
@@ -1,218 +1,32 @@
require 'spec_helper' #here in this same config/ dir
-describe "CsvPirate" do
- describe "#initialize" do
- before(:each) do
- @csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :gibbet => "",
- :aft => ".csv",
- :swab => :none,
- :mop => :clean,
- :waggoner => 'data'
- })
- end
-
- it "should return an instance of CsvPirate" do
- @csv_pirate.class.should == CsvPirate::TheCapn
- end
-
- it "should not export anything" do
- @csv_pirate.maroon.should == ""
- end
- end
-
- describe "#create" do
- before(:each) do
- @csv_pirate = CsvPirate::TheCapn.create({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :gibbet => "",
- :aft => ".csv",
- :swab => :none,
- :mop => :clean,
- :waggoner => 'data'
- })
- end
-
- it "should return an instance of CsvPirate" do
- @csv_pirate.class.should == CsvPirate::TheCapn
- end
-
- it "should store export in maroon instance variable" do
- @csv_pirate.maroon[0..100].should ==
- "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
- end
- end
-
-
- describe "#create with function-arg booty" do
- before(:each) do
- @csv_pirate = CsvPirate::TheCapn.create({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall"],
- :booty => [[:sub_name, 'a', 'Z'], :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :gibbet => "",
- :aft => ".csv",
- :swab => :none,
- :mop => :clean,
- :waggoner => 'data'
- })
- end
-
- it "should call instance functions with arguments an instance of CsvPirate" do
- @csv_pirate.maroon.should =~ /ProximZ CentZuri/
+describe CsvPirate do
+ describe "VERSION" do
+ it "should be a string" do
+ CsvPirate::VERSION.class.should == String
end
end
-
-
- describe "#hoist_mainstay" do
- before(:each) do
- @csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :gibbet => "",
- :aft => ".csv",
- :swab => :none,
- :mop => :clean,
- :waggoner => 'data'
- })
- end
-
- it "should return an instance of String" do
- @csv_pirate.hoist_mainstay.class.should == String
- end
-
- it "should return the export as a string" do
- @csv_pirate.hoist_mainstay[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
- end
-
- it "should store export in maroon instance variable" do
- @csv_pirate.maroon.should == ""
- @csv_pirate.hoist_mainstay
- @csv_pirate.maroon[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
+ describe "MAJOR" do
+ it "should be a string" do
+ CsvPirate::MAJOR.class.should == Fixnum
+ CsvPirate::MAJOR.should_not == ''
end
end
-
- describe "#old_csv_dump" do
-
- before(:each) do
- ["1/1/1998","2/2/2002","1/2/2003","3/2/2001","2/1/2007"].map {|x| Date.parse(x)}.each do |date|
- @csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall","dumps"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => date,
- :swab => :none,
- :mop => :clean
- })
- @csv_pirate.hoist_mainstay
- end
- end
-
- it "should find first (oldest) dump" do
- @new_csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall","dumps"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :brigantine => :first,
- :swab => :none,
- :mop => :clean
- })
- @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.19980101.export.csv"
- end
-
- it "should find last (newest) dump" do
- @new_csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall","dumps"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :brigantine => :last,
- :swab => :none,
- :mop => :clean
- })
- @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.20070201.export.csv"
+ describe "MINOR" do
+ it "should be a string" do
+ CsvPirate::MINOR.class.should == Fixnum
+ CsvPirate::MINOR.should_not == ''
end
end
-
- describe "#to_memory" do
-
- before(:each) do
- ["1/1/1998","2/2/2002","1/2/2003","3/2/2001","2/1/2007"].map {|x| Date.parse(x)}.each do |date|
- @csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall","dumps"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => date,
- :swab => :none,
- :mop => :clean
- })
- @csv_pirate.hoist_mainstay
- end
- end
-
- it "should return an array of 10 grubs built from data in CSV" do
- @new_csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall","dumps"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :brigantine => :last,
- :swab => :none,
- :mop => :clean
- })
- @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.20070201.export.csv"
- @new_csv_pirate.to_memory.class.should == Array
- @new_csv_pirate.to_memory.length.should == 10
+ describe "PATCH" do
+ it "should be a string" do
+ CsvPirate::PATCH.class.should == Fixnum
+ CsvPirate::PATCH.should_not == ''
end
end
-
- describe ":blackjack option" do
- before(:each) do
- @csv_pirate = CsvPirate::TheCapn.new({
- :grub => GlowingGasBall,
- :spyglasses => [:get_stars],
- :chart => ["spec","csv","GlowingGasBall"],
- :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
- :chronometer => false,
- :gibbet => "",
- :aft => ".csv",
- :swab => :none,
- :mop => :clean,
- :waggoner => 'data'
- })
- end
-
- it "should be {humanize => '_'} by default" do
- @csv_pirate.blackjack.should == {:humanize => '_'}
- @csv_pirate.hoist_mainstay
- @csv_pirate.maroon[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
- end
-
- it "should work as {:join => '_'}" do
- @csv_pirate.blackjack = {:join => '_'}
- @csv_pirate.blackjack.should == {:join => '_'}
- @csv_pirate.hoist_mainstay
- @csv_pirate.maroon[0..100].should == "name,distance,spectral_type,name_hash,name_next,name_upcase,star_vowels\nProxima Centauri,4.2 LY,M5.5V"
+ describe "BUILD" do
+ it "should be a string" do
+ [String, NilClass].include?(CsvPirate::BUILD.class).should == true
end
end
View
219 spec/the_capn_spec.rb
@@ -0,0 +1,219 @@
+require 'spec_helper' #here in this same config/ dir
+
+describe CsvPirate::TheCapn do
+ describe "#initialize" do
+ before(:each) do
+ @csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :gibbet => "",
+ :aft => ".csv",
+ :swab => :none,
+ :mop => :clean,
+ :waggoner => 'data'
+ })
+ end
+
+ it "should return an instance of CsvPirate" do
+ @csv_pirate.class.should == CsvPirate::TheCapn
+ end
+
+ it "should not export anything" do
+ @csv_pirate.maroon.should == ""
+ end
+ end
+
+ describe "#create" do
+ before(:each) do
+ @csv_pirate = CsvPirate::TheCapn.create({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :gibbet => "",
+ :aft => ".csv",
+ :swab => :none,
+ :mop => :clean,
+ :waggoner => 'data'
+ })
+ end
+
+ it "should return an instance of CsvPirate" do
+ @csv_pirate.class.should == CsvPirate::TheCapn
+ end
+
+ it "should store export in maroon instance variable" do
+ @csv_pirate.maroon[0..100].should ==
+ "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
+ end
+ end
+
+
+ describe "#create with function-arg booty" do
+ before(:each) do
+ @csv_pirate = CsvPirate::TheCapn.create({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall"],
+ :booty => [[:sub_name, 'a', 'Z'], :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :gibbet => "",
+ :aft => ".csv",
+ :swab => :none,
+ :mop => :clean,
+ :waggoner => 'data'
+ })
+ end
+
+ it "should call instance functions with arguments an instance of CsvPirate" do
+ @csv_pirate.maroon.should =~ /ProximZ CentZuri/
+ end
+ end
+
+
+ describe "#hoist_mainstay" do
+ before(:each) do
+ @csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :gibbet => "",
+ :aft => ".csv",
+ :swab => :none,
+ :mop => :clean,
+ :waggoner => 'data'
+ })
+ end
+
+ it "should return an instance of String" do
+ @csv_pirate.hoist_mainstay.class.should == String
+ end
+
+ it "should return the export as a string" do
+ @csv_pirate.hoist_mainstay[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
+ end
+
+ it "should store export in maroon instance variable" do
+ @csv_pirate.maroon.should == ""
+ @csv_pirate.hoist_mainstay
+ @csv_pirate.maroon[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
+ end
+ end
+
+ describe "#old_csv_dump" do
+
+ before(:each) do
+ ["1/1/1998","2/2/2002","1/2/2003","3/2/2001","2/1/2007"].map {|x| Date.parse(x)}.each do |date|
+ @csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall","dumps"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => date,
+ :swab => :none,
+ :mop => :clean
+ })
+ @csv_pirate.hoist_mainstay
+ end
+ end
+
+ it "should find first (oldest) dump" do
+ @new_csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall","dumps"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :brigantine => :first,
+ :swab => :none,
+ :mop => :clean
+ })
+ @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.19980101.export.csv"
+ end
+
+ it "should find last (newest) dump" do
+ @new_csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall","dumps"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :brigantine => :last,
+ :swab => :none,
+ :mop => :clean
+ })
+ @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.20070201.export.csv"
+ end
+ end
+
+ describe "#to_memory" do
+
+ before(:each) do
+ ["1/1/1998","2/2/2002","1/2/2003","3/2/2001","2/1/2007"].map {|x| Date.parse(x)}.each do |date|
+ @csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall","dumps"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => date,
+ :swab => :none,
+ :mop => :clean
+ })
+ @csv_pirate.hoist_mainstay
+ end
+ end
+
+ it "should return an array of 10 grubs built from data in CSV" do
+ @new_csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall","dumps"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :brigantine => :last,
+ :swab => :none,
+ :mop => :clean
+ })
+ @new_csv_pirate.brigantine.should == "spec/csv/GlowingGasBall/dumps/GlowingGasBall.20070201.export.csv"
+ @new_csv_pirate.to_memory.class.should == Array
+ @new_csv_pirate.to_memory.length.should == 10
+ end
+ end
+
+ describe ":blackjack option" do
+ before(:each) do
+ @csv_pirate = CsvPirate::TheCapn.new({
+ :grub => GlowingGasBall,
+ :spyglasses => [:get_stars],
+ :chart => ["spec","csv","GlowingGasBall"],
+ :booty => [:name, :distance, :spectral_type, {:name => :hash}, {:name => :next}, {:name => :upcase}, :star_vowels ],
+ :chronometer => false,
+ :gibbet => "",
+ :aft => ".csv",
+ :swab => :none,
+ :mop => :clean,
+ :waggoner => 'data'
+ })
+ end
+
+ it "should be {humanize => '_'} by default" do
+ @csv_pirate.blackjack.should == {:humanize => '_'}
+ @csv_pirate.hoist_mainstay
+ @csv_pirate.maroon[0..100].should == "Name,Distance,Spectral type,Name hash,Name next,Name upcase,Star vowels\nProxima Centauri,4.2 LY,M5.5V"
+ end
+
+ it "should work as {:join => '_'}" do
+ @csv_pirate.blackjack = {:join => '_'}
+ @csv_pirate.blackjack.should == {:join => '_'}
+ @csv_pirate.hoist_mainstay
+ @csv_pirate.maroon[0..100].should == "name,distance,spectral_type,name_hash,name_next,name_upcase,star_vowels\nProxima Centauri,4.2 LY,M5.5V"
+ end
+ end
+
+end

0 comments on commit d4c42aa

Please sign in to comment.
Something went wrong with that request. Please try again.