Skip to content

Commit

Permalink
Extract Method.
Browse files Browse the repository at this point in the history
  • Loading branch information
josemotanet committed Apr 29, 2013
1 parent 35aadd1 commit 087f3c9
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
40 changes: 40 additions & 0 deletions extract-method/lib/after.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Post

attr_reader :title, :date

def initialize title, date
@title = title
@date = date
end

def body
<<-RETURN
RANDOM TEXT Ladyship it daughter securing procured or am moreover mr. Put
sir she exercise vicinity cheerful wondered. Continual say suspicion
provision you neglected sir curiosity unwilling.
RETURN

end

def condensed_format
metadata
end

def full_format
return_string = metadata
return_string << "--\n#{body}"

return_string
end

private

def metadata
return_string = ''
return_string << "Title: #{title}"
return_string << "Date: #{date.strftime "%Y/%m/%d"}"

return_string
end

end
36 changes: 36 additions & 0 deletions extract-method/lib/before.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Post

attr_reader :title, :date

def initialize title, date
@title = title
@date = date
end

def body
<<-RETURN
RANDOM TEXT Ladyship it daughter securing procured or am moreover mr. Put
sir she exercise vicinity cheerful wondered. Continual say suspicion
provision you neglected sir curiosity unwilling.
RETURN

end

def condensed_format
return_string = ''
return_string << "Title: #{title}"
return_string << "Date: #{date.strftime "%Y/%m/%d"}"

return_string
end

def full_format
return_string = ''
return_string << "Title: #{title}"
return_string << "Date: #{date.strftime "%Y/%m/%d"}"
return_string << "--\n#{body}"

return_string
end

end
31 changes: 31 additions & 0 deletions extract-method/test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,34 @@

require 'before' if ENV["BEFORE"]
require 'after' unless ENV["BEFORE"]

describe Post do
before do
@date = Time.new(2014,02,28)
@post = Post.new("Fragmented Class", @date)
end

describe "when requested a condensed format" do

it "shows the post's title" do
@post.condensed_format.must_include "Fragmented Class"
end

it "shows the post's date" do
@post.condensed_format.must_include "2014/02/28"
end

end

describe "when requested a full format" do

it "shows the post's title" do
@post.full_format.must_include "Fragmented Class"
end

it "shows the post's date" do
@post.full_format.must_include "2014/02/28"
end

end
end

0 comments on commit 087f3c9

Please sign in to comment.