Forum: RSpec Pending expectations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3ff4f912c1aebaf3f73622cf4847ddc4?d=identicon&s=25 Sven S. (rubix)
on 2009-04-08 11:31
(Received via mailing list)
I've noticed that pending expectations fail if the before(:each) code is
not
implemented yet. In other words, taking the example code from Peepcode's
rspec
series:

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.

How come?
-sven
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-04-08 17:02
(Received via mailing list)
On Wed, Apr 8, 2009 at 2:11 AM, Sven <svoop@delirium.ch> wrote:

>  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.

///ark
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-08 17:10
(Received via mailing list)
On Wed, Apr 8, 2009 at 11:59 AM, Mark Wilden <mark@mwilden.com> wrote:
>>  it "should populate temperature units"
> 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
3ff4f912c1aebaf3f73622cf4847ddc4?d=identicon&s=25 Sven S. (rubix)
on 2009-04-08 17:10
(Received via mailing list)
> In general, I write before()
> after I write the examples, since I usually consider it just a DRY
> refactoring.

Good point. I guess I'll just get used to it then :-)
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-08 17:41
(Received via mailing list)
On Wed, Apr 8, 2009 at 6:11 AM, Sven <svoop@delirium.ch> wrote:
>  it "should populate zipcode"
>
> How come?

Please file a bug report at http://rspec.lighthouseapp.com and include
the backtrace you're getting.

Thanks,
David
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-08 22:58
(Received via mailing list)
On Wed, Apr 8, 2009 at 12:07 PM, Sven <svoop@delirium.ch> wrote:
>> In general, I write before()
>> after I write the examples, since I usually consider it just a DRY
>> refactoring.
>
> Good point. I guess I'll just get used to it then :-)

No, please don't get used to it. The behaviour you expect is correct,
and the behaviour you are seeing is incorrect.

Cheers,
David
3ff4f912c1aebaf3f73622cf4847ddc4?d=identicon&s=25 Sven S. (rubix)
on 2009-04-09 09:42
(Received via mailing list)
> No, please don't get used to it. The behaviour you expect is correct,
> and the behaviour you are seeing is incorrect.

Okidoke, I've submitted a ticket on Lighthouse.
This topic is locked and can not be replied to.