On Wed, Apr 8, 2009 at 11:59 AM, Mark Wilden <m...@mwilden.com> wrote:
> On Wed, Apr 8, 2009 at 2:11 AM, Sven <sv...@delirium.ch> wrote:
>
>> describe Weather, ".fetch for zipcode" do
>>
>>  before(:each) do
>>   �...@weather = Weather.fetch_for_zipcode(98117)
>>  end
>>
>>  it "should populate zipcode"
>>
>>  it "should populate temperature units"
>>
>>  it "should populate recorded at"
>>
>> end
>>
>> With rspec-1.2.0 this will result in 3 failing tests (as fetch_for_zipcode is
>> not yet implemented), whereas in the original screencast it caused the three
>> expectations to be reported as pending - which makes more sense to me.
>
> No one asked me, but I think the new way is better. If I write code,
> it should be correct. If I didn't care if the call to
> fetch_for_zipcode was correct, I'd comment it out, mock it out, or
> just not write it in the first place. In general, I write before()
> after I write the examples, since I usually consider it just a DRY
> refactoring.

No one asked me either, but I think Mark's approach is a valid
approach, but not the only approach :)

When writing specs with a describe/context structure, like this:

describe Thing do
  context "with no widgets" do
    before(:each) do
      @thing = Thing.new
    end
    it "acts one way"
  end

  context "with one widget" do
    before(:each) do
      @thing = Thing.new(:widgets => [Widget.new])
    end
    it "acts a different way"
  end
end

It is fairly common to write code to align with the context in the
before blocks. My expectation would be, in this case, that the before
blocks are not run unless there is at least one non-pending example in
the group.

FWIW,
David

>
> ///ark
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to