rspectest-reporting

Add extra documentation to rspec output


So, while I like Cucumber for its readability for integration testing and its ability to give us documentation we can share with the client easily, I also find it cumbersome from the development and testing speed standpoints.

I got to thinking today that if I could just print out messages to the RSpec documentation format that documented the "steps", then I could easily replicate the business features of Gherkin but in the simplicity of RSpec. But I can't figure out a way to do this.

What I want is to take something like this:

describe "Login and Authorization Tests" do
  before (:each) do
    docs "Given I have a user"
    @user = FactoryGirl.create(:user)
  end

  it "A user can belong to one or more user roles" do
    docs "And the user has no roles assigned"
    @user.roles.length.should eq 0
    docs "When I add two roles"
    @user.roles << FactoryGirl.create(:role)
    @user.roles << FactoryGirl.create(:role)

    @user.reload
    docs "Then the user should have two roles assigned"
    @user.roles.length.should eq 2        
  end
end

and get this in the documentation

User
  Login and Authorization Tests
    A user can belong to one or more user roles
      Given I have a user
      And the user has no roles assigned"
      When I add two roles
      Then the user should have two roles assigned

Note that the message from "before" shows up in the docs too, and would show up with that line in every test below it.

I'm thinking of forking to see if I can add something like this in, but before I did that, does anyone know if something like this is possible already?


Solution

  • I also contacted the RSpec dev team and someone there posted this add-on called rspec-longrun that could be repurposed for this. I haven't had a chance to try it yet, but it looks very promising. And as a bonus, it includes timing information.

    rspec-longrun: https://github.com/mdub/rspec-longrun

    Thread on rspec-dev: https://github.com/rspec/rspec-dev/issues/34