Created
October 13, 2011 20:02
-
-
Save janxious/1285340 to your computer and use it in GitHub Desktop.
A module version of the fast specs stuff from http://ariejan.net/2011/10/13/fast-specs-run-your-specs-in-less-than-1-second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
include Summarizeable | |
belongs_to :author | |
alias :body :summarizeable | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/models/summarizeable_spec.rb | |
require 'spec/helper' | |
describe Summarizeable do | |
context "summary" do | |
it "should return the summary" do | |
thing = SummaryStub.new | |
thing.text_to_summarize = "This is what I expect.\nI don't expect this!" | |
assert_equal "This is what I expect.", thing.summary | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Summarizeable | |
def summary(delimiter="\n") | |
matcher = /#{Regexp.escape(delimiter)}/i | |
@summary = if summarizeable =~ matcher | |
summerizeable.split(matcher).first.strip | |
else | |
summerizeable | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SummaryStub | |
include Summarizeable | |
attr_accessible :text_to_summarize | |
alias :text_to_summarize :summarizeable | |
end |
Sometimes. Probably not in this instance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summarizeable#summary creates the instance variable @summary. Is that appropriate behavior for a module?