Permalink
Browse files

Deletes those crapy tests and creates one big test file to be used as…

… documentation.
  • Loading branch information...
1 parent 23ccc36 commit d3bb3e18a3b172e930c73d3ce9028d23d76d37e2 @marano committed May 3, 2013
View
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
+ spec.add_development_dependency "pry"
spec.add_development_dependency "version"
spec.add_dependency "redcarpet"
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe Rollin::YearArchive do
- let (:article) { Rollin::Article.new('spec/fixtures/2013_05_01_My_first_post.mk') }
- subject (:month_archive) { Rollin::MonthArchive.new(2013, 05, [ article ]) }
- subject (:year_archive) { Rollin::YearArchive.new(2013, [ month_archive ]) }
-
- it 'tells the year' do
- year_archive.year.should == 2013
- end
-
- it 'has monthly archives' do
- year_archive.monthly_archive.size.should == 1
- year_archive.monthly_archive.first.should == month_archive
- end
-
- it 'has a list of articles' do
- year_archive.articles.first.should == article
- end
-end
View
@@ -1,33 +0,0 @@
-require './spec/spec_helper'
-
-describe Rollin::Article do
- subject (:article) { Rollin::Article.new('spec/fixtures/articles/2013_05_01_My_first_post.mk') }
-
- it 'tells article id' do
- article.id.should == '2013_05_01_My_first_post'
- end
-
- it 'tells article title' do
- article.title.should == 'My first post'
- end
-
- it 'compiles article body to html' do
- article.body.should == "<h2>This is my first post</h2>\n\n<p>And here we go!</p>\n"
- end
-
- it 'tells article year' do
- article.year.should == 2013
- end
-
- it 'tells article month' do
- article.month.should == 5
- end
-
- it 'tells article day' do
- article.day.should == 1
- end
-
- it 'tells article date' do
- article.date.should == Date.new(2013, 5, 1)
- end
-end
View
@@ -1,29 +0,0 @@
-require './spec/spec_helper'
-
-describe Rollin::Blog do
- context 'reading articles from articles folder' do
- subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures/articles') }
-
- it 'has the right amount of articles' do
- blog.articles.size.should == 4
- end
-
- it 'has monthly archives' do
- blog.monthly_archive.size.should == 3
- blog.monthly_archive.first.class.should == Rollin::MonthArchive
- end
-
- it 'has annual archives' do
- blog.annual_archive.size.should == 2
- blog.annual_archive.first.class.should == Rollin::YearArchive
- blog.annual_archive.first.monthly_archive.size.should == 2
- blog.annual_archive.first.monthly_archive.first.class.should == Rollin::MonthArchive
- blog.annual_archive.first.monthly_archive.first.articles.size.should == 2
- blog.annual_archive.first.monthly_archive.first.articles.first.class.should == Rollin::Article
- end
-
- it 'finds article by its id' do
- blog.find_article_by_id('2013_05_01_My_first_post').title.should == 'My first post'
- end
- end
-end
View
@@ -1,16 +0,0 @@
-describe Rollin::MonthArchive do
- let (:article) { Rollin::Article.new('spec/fixtures/2013_05_01_My_first_post.mk') }
- subject (:month_archive) { Rollin::MonthArchive.new(2013, 05, [ article ]) }
-
- it 'tells the year' do
- month_archive.year.should == 2013
- end
-
- it 'tells the month' do
- month_archive.month.should == 5
- end
-
- it 'has a list of articles' do
- month_archive.articles.first.should == article
- end
-end
View
@@ -0,0 +1,76 @@
+require 'spec_helper'
+
+# Fixtures
+#
+# 2013_05_01_My_first_post.mk
+# 2013_05_02_My_second_post.mk
+# 2013_06_01_My_third_post.mk
+# 2014_01_01_My_fourth_post.mk
+
+describe 'how rollin works' do
+
+ subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures') }
+
+ context 'retrieving posts' do
+ let (:first_article) { TestArticle.new(id: '2013_05_01_My_first_post', title: 'My first post', date: Date.new(2013, 5, 1)) }
+ let (:second_article) { TestArticle.new(id: '2013_05_02_My_second_post', title: 'My second post', date: Date.new(2013, 5, 2)) }
+ let (:third_article) { TestArticle.new(id: '2013_06_01_My_third_post', title: 'My third post', date: Date.new(2013, 6, 1)) }
+ let (:fourth_article) { TestArticle.new(id: '2014_01_01_My_fourth_post', title: 'My fourth post', date: Date.new(2014, 1, 1)) }
+
+ it 'gets articles' do
+ # articles
+
+ blog.should have(4).articles
+
+ blog.articles[0].should == first_article
+ blog.articles[1].should == second_article
+ blog.articles[2].should == third_article
+ blog.articles[3].should == fourth_article
+ end
+
+ it 'provides monthly archive' do
+ blog.monthly_archive.should have(3).articles
+
+ blog.monthly_archive[0].year.should == 2013
+ blog.monthly_archive[0].month.should == 5
+ blog.monthly_archive[0].should have(2).articles
+ blog.monthly_archive[0].articles.should include(first_article, second_article)
+
+ blog.monthly_archive[1].year.should == 2013
+ blog.monthly_archive[1].month.should == 6
+ blog.monthly_archive[1].should have(1).articles
+ blog.monthly_archive[1].articles.should include(third_article)
+
+ blog.monthly_archive[2].year.should == 2014
+ blog.monthly_archive[2].month.should == 1
+ blog.monthly_archive[2].should have(1).articles
+ blog.monthly_archive[2].articles.should include(fourth_article)
+ end
+
+ it 'provides annual archive' do
+ blog.should have(2).annual_archive
+
+ blog.annual_archive[0].year.should == 2013
+ blog.annual_archive[0].should have(2).monthly_archive
+ blog.annual_archive[0].monthly_archive[0].year.should == 2013
+ blog.annual_archive[0].monthly_archive[0].month.should == 5
+ blog.annual_archive[0].monthly_archive[0].should have(2).articles
+ blog.annual_archive[0].monthly_archive[0].articles.should include(first_article, second_article)
+ blog.annual_archive[0].monthly_archive[1].year.should == 2013
+ blog.annual_archive[0].monthly_archive[1].month.should == 6
+ blog.annual_archive[0].monthly_archive[1].should have(1).articles
+ blog.annual_archive[0].monthly_archive[1].articles.should include(third_article)
+ blog.annual_archive[0].should have(3).articles
+ blog.annual_archive[0].articles.should include(first_article, second_article, third_article)
+
+ blog.annual_archive[1].year.should == 2014
+ blog.annual_archive[1].should have(1).monthly_archive
+ blog.annual_archive[1].monthly_archive[0].year.should == 2014
+ blog.annual_archive[1].monthly_archive[0].month.should == 1
+ blog.annual_archive[1].monthly_archive[0].should have(1).articles
+ blog.annual_archive[1].monthly_archive[0].articles.should include(fourth_article)
+ blog.annual_archive[1].should have(1).articles
+ blog.annual_archive[1].articles.should include(fourth_article)
+ end
+ end
+end
View
@@ -3,3 +3,19 @@
Bundler.require :development
require './lib/rollin'
+
+class Rollin::Article
+ def ==(other)
+ id == other.id && title == other.title && date == other.date
+ end
+end
+
+class TestArticle
+ attr_reader :id, :title, :date
+
+ def initialize(properties)
+ @id = properties[:id]
+ @title = properties[:title]
+ @date = properties[:date]
+ end
+end

0 comments on commit d3bb3e1

Please sign in to comment.