Skip to content

Commit

Permalink
Add spec ApplicationHelper#days_of_a_month
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuosakurai committed Mar 30, 2013
1 parent 8f7d453 commit 8c97d4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ApplicationHelper

def days_of_a_month
days_of_the_week = %w( )
days_of_the_week = I18n.t('date.abbr_day_names')
days = []
(DateTime.now.beginning_of_month..DateTime.now.end_of_month).map do |datetime|
days << datetime.strftime("%Y/%m/%d(#{days_of_the_week[datetime.wday]})")
Expand Down
17 changes: 17 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe ApplicationHelper do
describe '#days_of_a_month' do
let(:now) { Time.now }
subject { helper.days_of_a_month }

This comment has been minimized.

Copy link
@tatsuosakurai

tatsuosakurai Apr 7, 2013

Author Owner

ここでsubjectの設定してます

describe 'size' do
it { subject.size.should == Time.days_in_month(now.month) }

This comment has been minimized.

Copy link
@tatsuosakurai

tatsuosakurai Apr 7, 2013

Author Owner

subject の中身は helper.days_of_a_month になります。

end
describe 'first' do
it { subject.first.should == now.beginning_of_month.strftime("%Y/%m/%d(#{I18n.t('date.abbr_day_names')[now.beginning_of_month.wday]})") }
end
describe 'last' do
it { subject.last.should == now.end_of_month.strftime("%Y/%m/%d(#{I18n.t('date.abbr_day_names')[now.end_of_month.wday]})") }
end
end
end

2 comments on commit 8c97d4b

@vestige
Copy link

@vestige vestige commented on 8c97d4b Apr 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このテストがまったくわからないのでどういうテストなのか教えて欲しいー。
subject.size.shouldってどういうのが帰ってくるのかな?

@tatsuosakurai
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考
"RSpec の入門とその一歩先へ - t-wadaの日記" http://d.hatena.ne.jp/t-wada/20100228/p1
"RSpecによるユニットテストの書き方 - tech.recompile.net" http://tech.recompile.net/post/21340599029/rspec

Please sign in to comment.