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 7772339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:52:00+00:00 2026-06-01T16:52:00+00:00

I have a request spec that looks like this: describe Registering from the main

  • 0

I have a request spec that looks like this:

describe "Registering from the main page" do
  before(:each) do
    fill_in "username","my_username"
    fill_in "password","my_password"
    fill_in "password_confirmation","my_password"
    click_button "Register"
  end

  it "should have created a new user" do
    User.count.should == 1
  end

  it "should have changed the message on the homepage" do
    find("#element").value.should == "You registered!"
  end

  # ... other tests like this
end

First question, how can I make sure I have 0 users before submitting the form?

Second, that before doesn’t quite seem right to me, even though it does the job. Is there another way of writing the tests for this whole registering use case? Perhaps reformulate the before part somehow, or is it acceptable the way I’m doing it?

UPDATE: I changed the before(:all) to before(:each) because tests started to fail. The body of the response seems to be incomplete when I’m using before(:all). Do you happen to know why?

  • 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-01T16:52:01+00:00Added an answer on June 1, 2026 at 4:52 pm

    You can can use the change() matcher so as not to have to worry about what the count is beforehand:

    lambda { click_button("Register") }.should change{ User.count }.by(1)
    

    If you really want it to specifically go from 0 to 1, you can do this:

    lambda { click_button("Register") }.should change{ User.count }.from(0).to(1)
    

    To answer the question about before(:all) and before(:each), before(:each) will get called once before each example (it block), whereas before(:all) gets called only once before all examples in the describe block. This is why before(:all) is generally not recommended, since, if any of your examples change something about the initial state, later examples will be affected.

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

Sidebar

Related Questions

I have a request in from a client that would like one of their
I have a request for some contract work from an organization that uses Excel
I have a SOAP request that is known to work using a tool like,
I have a WCF client that needs to generate a request containing this XML
I have 100 web servers and noticed that some of them have request filtering
I have a request that returns a JSON object with a single property which
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
I have a Group model that I am testing using Request specs with Capybara
I have a shell script which I'd like to trigger from a J2EE web
I have request where i need to change grid formatting on drop down action

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.