Skip to content

Commit

Permalink
Put all specs under the Treat::Specs module.
Browse files Browse the repository at this point in the history
  • Loading branch information
louismullie committed Jan 7, 2013
1 parent e2b813c commit 8b8a769
Show file tree
Hide file tree
Showing 16 changed files with 1,269 additions and 1,231 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace :treat do
task :spec, [:language] do |t, args|
require_relative 'spec/helper'
Treat::Specs::Helper.start_coverage
Treat::Specs::Helper.run_core_specs
Treat::Specs::Helper.run_library_specs
Treat::Specs::Helper.run_language_specs(args.language)
end

Expand Down
54 changes: 29 additions & 25 deletions spec/entities/collection.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
describe Treat::Entities::Collection do
module Treat::Specs::Entities

describe Treat::Entities::Collection do

before :all do
@file = Treat.paths.spec +
'workers/examples/english/mathematicians'
end
before :all do
@file = Treat.paths.spec +
'workers/examples/english/mathematicians'
end


describe "Buildable" do
describe "Buildable" do

describe "#build" do
describe "#build" do

context "when supplied with an existing folder name" do
context "when supplied with an existing folder name" do

it "recursively searches the folder for " +
"files and opens them into a collection of documents" do
collection = Treat::Entities::Collection.build(@file)
collection.size.should eql 6
end
it "recursively searches the folder for " +
"files and opens them into a collection of documents" do
collection = Treat::Entities::Collection.build(@file)
collection.size.should eql 6
end

end
end

context "when supplied a folder name that doesn't exist" do
context "when supplied a folder name that doesn't exist" do

it "creates the directory and opens the collection" do
f = Treat.paths.spec + 'workers/examples/english/test'
c = Treat::Entities::Collection.build(f)
FileTest.directory?(f).should eql true
c.should be_an_instance_of Treat::Entities::Collection
FileUtils.rm_rf(f)
it "creates the directory and opens the collection" do
f = Treat.paths.spec + 'workers/examples/english/test'
c = Treat::Entities::Collection.build(f)
FileTest.directory?(f).should eql true
c.should be_an_instance_of Treat::Entities::Collection
FileUtils.rm_rf(f)
end
end
end
end

end
end

describe "#<<" do
describe "#<<" do

it "adds the object to the collection" do
f = Treat.paths.spec + 'workers/examples/english/economist'
Expand All @@ -43,6 +45,8 @@
c.size.should eql 4
end

end

end

end
Expand Down Expand Up @@ -105,4 +109,4 @@
end
end
=end
=end
89 changes: 45 additions & 44 deletions spec/entities/document.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
describe Treat::Entities::Document do

describe "Buildable" do

describe "#build" do

context "when supplied with a readable file name" do
it "opens the file and reads its " +
"content into a document" do
f = Treat.paths.spec +
'workers/examples/english/mathematicians/leibniz.txt'
d = Treat::Entities::Document.build(f)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Gottfried Leibniz').should_not eql nil
module Treat::Specs::Entities
describe Treat::Entities::Document do

describe "Buildable" do

describe "#build" do

context "when supplied with a readable file name" do
it "opens the file and reads its " +
"content into a document" do
f = Treat.paths.spec +
'workers/examples/english/mathematicians/leibniz.txt'
d = Treat::Entities::Document.build(f)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Gottfried Leibniz').should_not eql nil
end
end
end

context "when supplied with a url" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file" do
url = 'http://www.rubyinside.com/nethttp-cheat-sheet-2940.html'
d = Treat::Entities::Document.build(url)
d.format.should eql 'html'
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Rubyist').should_not eql nil
context "when supplied with a url" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file" do
url = 'http://www.rubyinside.com/nethttp-cheat-sheet-2940.html'
d = Treat::Entities::Document.build(url)
d.format.should eql 'html'
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Rubyist').should_not eql nil
end
end
end

context "when supplied with a url with no file extension" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file, assuming " +
"the downloaded file to be in HTML format" do
url = 'http://www.economist.com/node/21552208'
d = Treat::Entities::Document.build(url)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Ronnie Lupe').should_not eql nil
context "when supplied with a url with no file extension" do
it "downloads the file the URL points to and opens " +
"a document with the contents of the file, assuming " +
"the downloaded file to be in HTML format" do
url = 'http://www.economist.com/node/21552208'
d = Treat::Entities::Document.build(url)
d.should be_an_instance_of Treat::Entities::Document
d.to_s.index('Ronnie Lupe').should_not eql nil
end
end
end

context "when called with anything else than a " +
"readable file name or url" do

it "raises an exception" do
lambda do
Treat::Entities::Document.build('nonexistent')
end.should raise_error

context "when called with anything else than a " +
"readable file name or url" do

it "raises an exception" do
lambda do
Treat::Entities::Document.build('nonexistent')
end.should raise_error
end

end

end

end

end

end
end
Loading

0 comments on commit 8b8a769

Please sign in to comment.