Hacker News new | ask | show | jobs
by theptip 2067 days ago
Would you say Rspec is better than the Python equivalents like behave or pytest-BDD? Curious as I've never worked with Ruby/Rails but I'm aware there are some things that are way ahead of other toolchains (and others that are way behind as you've noted).
3 comments

RSpec is definitely better, but I've mimicked it this way with pytest because I didn't like each Given/When decorator in pytest-bdd requiring a separate method to setup. It was way too verbose. I want to be able to quickly nest them, like in RSpec.

So I do:

  TestSomeMethod:
      TestWhenDateProvided:
           def test_it_does_not_use_system_date(fixture, ...):
           assert ...

      TestWhenDateNotProvided:
           def test_it_uses_system_date(fixture, ...):
           assert ...
Ah so you’d say the nested setup is one thing that differentiates Rspec.

I’d use inherited test classes for this case, either sharing the setup in the parent and having each child define their own tests, or defining the test cases in the parent and overriding the setup in the child classes.

Seems like the latter might be hard in Rspec? But the former sounds more concise in the Rspec notation, I agree. I think Ruby’s anonymous blocks seem to be the differentiator in the toolset, I’ve not seen a Python DSL that’s as good in that regard.

Define "better". The mocking story and the rspec syntax itself is insanely better than in python. But the actual internals are pretty much comparable in my opinion.
Yes. I would use the tooling inspired by the Ruby tools like factory boy and stick with pytest over behave, personally. I’ve not used pytest-bdd.

In JS mocha or jest are both great.