Skip to content

Instantly share code, notes, and snippets.

@biscuitvile
Created April 18, 2012 19:48
Show Gist options
  • Save biscuitvile/2416064 to your computer and use it in GitHub Desktop.
Save biscuitvile/2416064 to your computer and use it in GitHub Desktop.
Fast specs
class PostPresenter < BasePresenter
presents :post
def published
created_at.to_s(:date_long)
end
def author
post.author_name
end
def byline
"By #{post.author.first}, #{published}"
end
end
require File.join(File.dirname(__FILE__), '../../app/presenters', 'post_presenter')
describe PostPresenter do
let (:post) { stub 'post' }
let (:template) { stub 'template' }
let (:presenter) { PostPresenter.new(post, template) }
context "#published" do
it "formates the created_at timestamp" do
post.stub_chain(:created_at, :to_s).with(:date_long) { "Mar 15th, 2012" }
presenter.published.should == "Mar 15th, 2012"
end
end
context "#author" do
it "returns the author's name" do
post.stub(:author_name) { "John Doe" }
presenter.author.should == "John Doe"
end
end
context "#byline" do
it "formats the author first name and published date" do
post.stub_chain(:author, :first) { 'John' }
presenter.stub(:published) { '12/31/99' }
presenter.byline.should == "By John, 12/31/99"
end
end
end
module EmployeeExtensions
module ReviewEligibility
def non_applicable_for_review?
has_unended_leave? || terminated? || pending_termination?
end
def overdue_for_review?
current_position_assignments.any? {|a| a.overdue_for_review?}
end
def due_for_review?
current_position_assignments.any? {|a| a.pending_review?}
end
end
end
require 'employee_extensions/review_eligibility'
describe "Review Eligibility" do
let (:employee) {
stub.extend(EmployeeExtensions::ReviewEligibility).as_null_object
}
context "#non_applicable_for_review?" do
it "true if employee has an open ended leave of absence" do
employee.stub(:has_unended_leave?) { true }
employee.non_applicable_for_review?.should be_true
end
it "true if employee is terminated" do
employee.stub(:has_unended_leave?) { false }
employee.stub(:terminated?) { true }
employee.non_applicable_for_review?.should be_true
end
it "true if employee is is pending termination" do
employee.stub(:pending_termination?) { true }
employee.non_applicable_for_review?.should be_true
end
end
context "#overdue_for_review?" do
it "true when any of its position assignments are overdue for review" do
pos = stub 'position_assignment', :overdue_for_review? => true
employee.stub(:current_position_assignments) { [pos] }
employee.overdue_for_review?.should be_true
end
end
context "#due_for_review?" do
it "true when any of its position assignments are due_for review" do
pos = stub 'position_assignment', :pending_review? => true
employee.stub(:current_position_assignments) { [pos] }
employee.due_for_review?.should be_true
end
end
end
module PayRateExtensions
module SalaryConversion
def amount_as_hourly
if frequency == 'year'
(amount / 52) / 45
else
amount
end
end
end
end
require 'pay_rate_extensions/salary_conversion'
describe "Salary Conversion" do
let (:pay_rate) {
stub.extend(PayRateExtensions::SalaryConversion).as_null_object
}
context "#amount_as_hourly" do
context "when the frequency is year" do
it "converts the salaried amount to hourly" do
pay_rate.stub(:frequency) { 'year' }
pay_rate.stub(:amount) { 50000.00 }
pay_rate.amount_as_hourly.should == 21.367521367521366
end
end
context "when the frequency is not year" do
it "returns the hourly amount" do
pay_rate.stub(:frequency) { 'hour' }
pay_rate.stub(:amount) { 8.25 }
pay_rate.amount_as_hourly.should == 8.25
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment