lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.4k stars 185 forks source link

doc: uses pending in describe block / pattern to skip all tests in a describe block #610

Open blueyed opened 5 years ago

blueyed commented 5 years ago

http://olivinelabs.com/busted/ has this section:

Pending
Pending functions are placeholders for tests you plan to write (or fix) later.

describe("busted pending tests", function()
  pending("I should finish this test later")
end)

However, according to https://github.com/Olivine-Labs/busted/issues/551#issuecomment-305960557 this does not work.

Usually you would use pending instead of it then. So the docs need to be fixed in this regard (I could not find them in some git repo).

Is this a good pattern to make all tests in a describe block pending then?

describe("foo", function()
  if some_condition then
    it = pending
  end
  it("works", function()
    error("foo")
  end)
end)

(in https://github.com/neovim/neovim/pull/10701/commits/f6c94124368bd14a83e83d4f172b8939d0503daf return was used, but that does not really make the tests pending, but only skips them)

DorianGray commented 5 years ago

@Tieske wrote some tests in https://github.com/Olivine-Labs/busted/pull/583 that show that not working. It's on my list to go in and fix that =)

As long as you have test insulation enabled that will work fine. iirc you can replace describe with pending as well, but I may be mis-remembering.

blueyed commented 4 years ago

While the it = pending trick works (but should rather be local it = pending(" (reason)"), it is different from calling pending in it still, which would add the location for the pending call.

This works quite good:

    local function pending_it(reason, it)
      return function(desc)
        it(desc, function()
          pending(desc.." ("..reason..")")
        end)
      end
    end
    local it = pending_it("reason!", it)

I think it would be good if using pending("reason") in a describe block would internally turn all it blocks into pending ones like the above, but that would break the existing behavior, where local it = pending("…") would be used.

The above pending_it function would benefit from pending therein (which is busted.pending) would be abled to handle level, similar to how busted.error does it, so that the location would be reported properly.

I think for me local it = pending(…) is better then the wrapper (pending_it), mainly because of the missing level, and that it would add additional lines for the location after all (even with adjusted level not really that useful).

Tieske commented 3 years ago

after #636 was merged, this should now work. Can you confirm @blueyed ? and if so, close this issue?