[TIP] running away from RSpec

vanderson.mota at gmail.com vanderson.mota at gmail.com
Sat Feb 12 11:36:00 PST 2011


> Probably the most common (and understandable) answer is that Python syntax
> wouldn't allow such a thing
> whereas in Ruby it is possible.

not syntax exactly. Rspec monkeypatches every object inside of its
scope, inserting the methods "should" and "should_not". You can do
something in python, but you can't monkeypatch the built-in types.

If you want something like rspec, there is should_dsl.
https://github.com/hugobr/should-dsl

> This more of an open question I guess, but why there isn't a project in
> Python that grabs the best features from RSpec
> and implements them?

I don't see a HUGE advantage in using "value.should be_true" instead
of assertTrue(value). It's a matter of taste.

The thing i like in Rspec is that you can have subcontexts in your
tests/specs, like this:

describe "login" do

  ..code..

   context "success" do
     ....code...
   end

   context "failure" do
     ...code...
   end
end

It makes easier to keep your tests more organized. You can achieve
such organization with unittest/unittest2, but will require a little
more work.
The only thing i would like in unittest is if the asserts were
functions instead of methods. But this is a "nice-to-have". I can live
with asserts as methods.

Talking about the Rspec mocks:

I don't like all that names... mocks, stubs... etc. I prefer to use
mock.py, because it's much more simpler, IMHO.

The only thing i think its a mistake is it to try to make a testing
tool that looks like Ruby. The better ports happen when you apply the
most intention than implementation. The RSpec makes tests easier to
write and maintain, in "ruby world". And works pretty well.

Python have such projects, like nose, pytest, etc and they're doing
quite a good job.


Which features you like in Rspec, despite teaching english to the
interpreter? ;-p


Cheers!

2011/2/12 Alfredo Deza <alfredodeza at gmail.com>
> For the past few weeks I have been thinking a lot about RSpec and why there
> is no clear, definite answer when
> someone asks:
>  "I'm looking for a Python equivalent of RSpec. Where can I find such a
> thing?"
> Probably the most common (and understandable) answer is that Python syntax
> wouldn't allow such a thing
> whereas in Ruby it is possible.
> Ok, if that is so, then why there are so many projects (most of them already
> un-maintained) that try to give
> some RSpec features to Python?
> There is Pinocchio written in part by Titus (last commit was in 2009), there
> is a spec runner that Gary wrote, there is also
> pyspec (last version from 2008) and a couple of others. I know there is
> "lettuce" which tries to emulate Ruby's Cucumber
> but that is not exactly RSpec.
> So are we running away from RSpec just because we can't implement it in
> Python? (or maybe we do want to implement it
> and then we fail?).
> This more of an open question I guess, but why there isn't a project in
> Python that grabs the best features from RSpec
> and implements them?
> Isn't that how we came about UnitTesting? (e.g. "hey that's JUnit and seems
> good let's implement that in Python")
> Not trying to start a flamewar here, but I guess at some level it is healthy
> to ask these kind of questions, specially since
> a lot of the guys in this list are so important for the Python testing
> environment.
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
>



-- 
Vanderson Mota dos Santos



More information about the testing-in-python mailing list