In general, yes, I've also found it useful to express pre-conditions as 
expectations in some situations.  I usually do this when I've realized that 
the test I'm writing has a non-obvious assumption that, if it was ever 
violated due to a config change or some other change, would cause the test 
to pass without exercising the code I intend it to.  You don't want a 
future change to cause a test to start passing only because it's no longer 
exercising the logic it is intended to cover.

That said, in the example you gave, it's not clear to me what the value is. 
 Are you concerned that `build` might one day change to no longer return a 
Hash?

HTH,
Myron

On Friday, September 2, 2016 at 5:25:46 AM UTC-7, Panayotis Matsinopoulos 
wrote:
>
> Hi,
>
> I would like to have your opinion on the following.
>
> I have found very useful to verify the context of an example. What do I 
> mean? See the following example:
>
> describe MyClass do
>   describe '#process' do
>     context 'when something is a Hash' do
>        let(:something) { build(:something) }
>
>        before do
>           expect(something).to be_a(Hash)
>        end
>
>        it 'returns an open struct' do
>          expect(subject.process(something)).to be_a(OpenStruct)
>        end
>     end
>   end
> end
>
> Do you see that in the before block I am verifying that the context of the 
> "it" is correct?
>
> To me, this has been proven very useful. Because sometimes, the context 
> setup code might not be doing what we are expecting it to do. The 
> verification code does the double check.
>
> What is your opinion about this practice? Is this a practice that you 
> apply too? Or am I overprotective?
>
> Panos
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/19b746ee-acec-4c99-9dc6-b87d43aa896d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to