[rspec-users] Can I set subject to its own method call?

Andrew Timberlake andrew at andrewtimberlake.com
Thu Jan 5 11:31:59 EST 2012

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)

Hope that helps.


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-users at rubyforge.org (mailto:rspec-users at rubyforge.org)
> http://rubyforge.org/mailman/listinfo/rspec-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120105/302a17ba/attachment.html>

More information about the rspec-users mailing list