Thanks, I was using another way before until I properly read through the rspec doc.
I was doing this in another example: let(:instance) { described_class.new() } describe ' subject { instance.parse_log() } its([:duration]){ should == mock_duration} its([:owner]){ should == mock_editor} I guess it just feels more natural to me to put the describe method call in the center of the spec, which is the subject. And it is more abbreviated (I don't have to put a shoulda in a it block which is three lines). On 1月6日, 上午12時31分, Andrew Timberlake <and...@andrewtimberlake.com> wrote: > Why don't you use let: > > describe MyClass do # Will set subject to an instance > of MyClass > context '#parse_input' do > let(:input) { subject.parse_input } # calling input in your specs > will now return the result of parse_input > > it 'is a hash' do > input.should be_a(Hash) # This evaluates let(:input) > end > end > end > > Hope that helps. > > Andrew > > On Thursday 05 January 2012 at 11:26 AM, m wrote: > > > > > > > > > The symbol "subject" by default is an instance of the described class. > > In some method testing I often want to set the subject to be a method > > call to the instance, for example "city.parse_input()". > > > I tried to do > > > describe '#parse_input' do > > subject{ subject.parse_input() } #returns hash > > ... > > end > > > but I can't. > > > I want to ask where did I get the semantic of this subject command > > wrong which prevent me from doing this. Thanks. > > _______________________________________________ > > rspec-users mailing list > > rspec-us...@rubyforge.org (mailto:rspec-us...@rubyforge.org) > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users