Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm missing this particular feature in T::U that I have in RSpec -- nested contexts + lets/subjects blocks.

    context "parent" do
      subject { Factory(:something, :value => other_thing) }
      let(:other_thing) { "Value" }
      it "has 'Value' value" do
        subject.value.should == "Value"
      end

      context "nested" do
        let(:other_thing) { "Totally other value" }
        it "has 'Totally other value' value" do
          subject.value.should == 'Totally other value'
        end
      end
    end


You might be interested in contest[1], which adds a thin layer of sugar over Test::Unit.

In addition to nested contexts, it also lets you provide your test name as a string rather than a method name, to avoid wearing out your underscore key with "def test_new_instance_should_respond_to_foo".

[1] https://github.com/citrusbyte/contest/blob/master/lib/contes...


Have you looked at Shoulda? It lets you use contexts and adds to the goodness of Test::Unit at the same time.


Exactly. I only alluded briefly to Shoulda (and Coulda) in my post. I live and die by them.

Context is king.

BTW, while I may beat up on RSpec, I learned much of how I perceive TDD indirectly from David Chelimsky. I may not be an RSpec fan any more but I'm a huge David fan.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: