<br><br><div class="gmail_quote">On Sat, Feb 12, 2011 at 2:58 PM, Gary Bernhardt <span dir="ltr">&lt;<a href="mailto:gary.bernhardt@gmail.com">gary.bernhardt@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Sat, Feb 12, 2011 at 10:34 AM, Alfredo Deza &lt;<a href="mailto:alfredodeza@gmail.com">alfredodeza@gmail.com</a>&gt; wrote:<br>
&gt; This more of an open question I guess, but why there isn&#39;t a project in<br>
&gt; Python that grabs the best features from RSpec<br>
&gt; and implements them?<br>
<br>
</div>As you suggest, it&#39;s impossible. Mote and PySpec are just fancy ways<br>
to name your tests: weak implementations of one tiny corner of RSpec.<br>
Mote uses horrible settrace magic; PySpec adds a bunch of<br>
domain-irrelevant noise. Neither even supports arbitrary context<br>
strings. RSpec is more terse, more expressive, removes the noise, and<br>
is an entirely reasonable thing to build in Ruby.<br>
<br>
That last point is important: it&#39;s not just that RSpec is possible in<br>
Ruby; it&#39;s actually idiomatic. I think that people don&#39;t realize just<br>
how easy it is to build its syntax. RSpec lets you say things like:<br>
<br>
  describe Integer do<br>
    it &quot;adds numbers&quot; do<br>
      (1 + 1).should == 2<br>
    end<br>
  end<br>
<br>
Looks complicated and magical, right? Nope. Here&#39;s an implementation<br>
of describe and it:<br>
<br>
  def describe(name)<br>
    puts name<br>
    yield<br>
  end<br>
<br>
  def it(name)<br>
    puts &quot;- #{name}&quot;<br>
    yield<br>
  end<br>
<br>
This will output the spec output that&#39;s become so familiar:<br>
<br>
  Integer<br>
  - adds numbers<br>
<br>
I spent a couple days of my life trying to get Python to do this when<br>
writing Mote and failed completely.<br>
<br>
The `2.should == 2` syntax is also simple, but here you can get close<br>
in Python. Expecter Gadget [1] lets you say `expect(1 + 1) == 2`. I<br>
still prefer RSpec because the statement reads as &quot;subject,<br>
relationship, expected value&quot;.<br>
<br>
There&#39;s much more terseness to be had than this, though; the above is<br>
just the most trivial example. You can say things like:<br>
<br>
  describe Dog do<br>
    it { should have(4).feet }<br>
    it { should be_thirsty }<br>
  end<br>
<br>
This is totally stock RSpec (and totally self-contained).<br>
`have(4).feet` asserts that `Dog.new.feet.size == 4`; `be_thirsty`<br>
asserts that `Dog.new.thirsty?` returns true.<br>
<br>
The most equivalent Python is:<br>
<br>
    class DogTest:<br>
        def setup(self):<br>
            self.dog = Dog()<br>
<br>
        def test_that_it_has_4_feet(self):<br>
            assert len(self.dog.feet) == 4<br>
<br>
        def test_that_it_is_thirsty(self):<br>
            assert self.dog.is_thirsty()<br>
<br>
(Inline the dog construction if you like; that just moves the problem around.)<br>
<br>
Some Python programmers will probably turn their noses up at that<br>
RSpec example because it&#39;s fancy (I know I would&#39;ve). I think that&#39;s<br>
unreasonable. It&#39;s significantly more terse *and* more readable than<br>
the Python: a combination we don&#39;t often get.<br></blockquote><div><br></div><div>It is *very* difficult to talk about things that exist in other languages that are great</div><div>and that they do not exist in Python.</div>

<div><br></div><div>It is also not a case of &quot;if you like it so much just use BLEH&quot;. I just think we can</div><div>come up with different and better things and should be talking about that too. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


<br>
&quot;More readable&quot; does depend on learning RSpec, but that&#39;s easy because<br>
it&#39;s so intuitive. And I bet that you knew exactly what it meant upon<br>
reading it, even if its mapping onto the Dog class wasn&#39;t obvious.<br>
<br>
Getting back to the point: you just can&#39;t do this stuff in Python.<br>
I&#39;ve spent a lot of time over the last couple years thinking about<br>
this and eventually I just gave up.</blockquote><div><br></div><div>I think that is why it is important to talk about stuff that is not necessarily tied to</div><div>UnitTesting and the way things are currently done.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> It&#39;s one of the reasons that<br>
almost all of my programming is now done in Ruby.</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
[1] <a href="https://github.com/garybernhardt/expecter" target="_blank">https://github.com/garybernhardt/expecter</a><br>
<font color="#888888"><br>
--<br>
Gary<br>
<a href="http://blog.extracheese.org" target="_blank">http://blog.extracheese.org</a><br>
</font></blockquote></div><br>