Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8257823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:19:44+00:00 2026-06-08T02:19:44+00:00

I’d like to be able to write a spec such as describe Foo do

  • 0

I’d like to be able to write a spec such as

describe Foo do
    before :each do
        @hash = some_very_expensive_setup_op
    end
    describe "hash" do
        subject{@hash}
        its([:a]){should == 10}
        its([:b]){should == 20}
        its([:c]){should == 30}
    end
end

And the way RSpec works, quite reasonably, is to execute the before block before each its block. In many cases this is what you want but in the above case and in many of my tests the final leaf its blocks are making assertions that have no side effects.

I could rewrite the spec as

describe Foo do
    before :each do
        @hash = some_very_expensive_setup_op
    end
    describe "hash" do
        it "should have some attributes" do
            @hash[:a].should == 10
            @hash[:b].should == 20
            @hash[:c].should == 30
        end
    end
end

Now all the assertions are made within a single block. The spec is functionally identical but I don’t get the juicy reporting of the first version listing each assertion in the documentation formatter.

The output is important to me because I try to use the output as documentation for consumers of the web api. For example for one of my specs I have an output like

GET /status.json?ago=:ago
  it should behave like authenticated
    GET /status.json
      accepts a valid user
      rejects an invalid user
  request
    request attributes
      :ago - number of seconds of history to calculate statistics
      :current_user ( implicit )
    response attributes
      scale
      downtime
      points
      nextlevel

But as the number of attributes rises it slows down the specs.

Are there any solutions to this tension between fine grained reporting
output and test performance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:19:46+00:00Added an answer on June 8, 2026 at 2:19 am

    The solution is to use packages like https://github.com/LRDesign/rspec-steps

    steps "Login and change password" do
       it "should show the login form" do
         visit root
         page.should have_text "Login"
       end
    
       it "should successfully log in" do
         fill_in :name, "Johnny User"
         click "Login"
         page.should have_text "Welcome, Johnny!"
       end
    
       it "should load the password change form" do 
         click "My Settings"
         click "Update Password"
         page.should have_selector("form#update_password")
       end     
    
       it "should change the user's password successfully" do
         fill_in :password, "foobar"
         fill_in :password_confirmation, "foobar"
         click "Change Password"
         page.should have_text "Password changed successfully!"
         User.find_by_name("Johnny User").valid_password?("foobar").should be_true 
       end
    
     end
    

    State is maintained between it calls you can test a sequence of steps if you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.