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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:15:44+00:00 2026-05-29T15:15:44+00:00

tl;dr: Jump to the last paragraph Recently I’ve been trying to use RSpec’s request

  • 0

tl;dr: Jump to the last paragraph

Recently I’ve been trying to use RSpec’s request specs to do some more targeted testing.

This is how my testing mostly looks:

  • general cucumber feature specification, i.e. user goes to a post with comment, upvotes on a comment and the author gets points
  • model specs for when the model actually has some functinality, i.e. User#upvote(comment)
  • controller specs where I stub most of the things and just try to make sure the code goes the way I expect
  • view specs for when there is something complex in the view, such as rendering a upvote link only when the user didn’t already upvote, and these are stubbed as well

The problem is when I have some specific scenario which causes a bug and everything seems to work in the model/view layer where I am unable to reproduce it.

That forces me to write an integration test, which I can also do in cucumber. The problem arises once I am able to actually reproduce it, and I need to figure out why is it happening. This usually means playing around in tests, changing different things and seeing what happens.

For example create a comment that is owned by the user who is trying to upvote, try to vote with an expired session etc. However these are really huge pain to write in Cucumber, because of the need to write a scenario and then specify each step.

At this point, I prefer to write a request spec, because it is more low level and allows me to directly do stuff. The problem is, that I’m not really sure how to properly write a request spec, or what are the rules.

A simple example here is:

visit login_path
fill_in "Username", :with => user.username
fill_in "Password", :with => user.password
click_button "Log in"

vs

post sessions_path(:username => user.username, :password => user.password)

or even something more low level like

session[:user_id] = user.id # this actually doesn't work, but the idea is there

Both of these examples achieve the same thing, they’ll log a user in. I know that the answer to which one to pick is based on what I need to test, but that doesn’t answer the correct, conventional way to do this.

I’ve been trying to find something about request specs, but they’re not really described anywhere. The RSpec book doesn’t cover them, the RSpec documentation doesn’t say anything either.

What is a correct way to write request specs? When should I use capybara and when just the Rails’ #get and #post methods instead of clicking buttons and visiting paths?

  • 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-05-29T15:15:44+00:00Added an answer on May 29, 2026 at 3:15 pm

    For requests spec I believe the convention is to stick to testing user behaviour and interface interactions, which would mean loading the page, filling in the form etc. A website user cant set the session or interact with variables directly so neither should your request specs.

    I’ve often been tempted to skip page loads and form interactions by posting or setting variables in request specs (for speeds sake, especially heavy ajax specs) but it really does break the purpose of a request spec.

    As the comments mentioned, you should test the specific controller / view behaviour in the other spec types.

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

Sidebar

Related Questions

I'm trying to jump through some hoops to organize data in a special way.
(Quick version: jump to paragraph next to the last one - the one beginning
is there any way of quick jump to the last modified line? eclipse has
Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving
Jump Game: Given an array, start from the first element and reach the last
When I use vim's quickfix to jump to errors in my build, if the
I have been developing a project in python for the last six months, and
I am trying to secure my PHP Image upload script and the last hurdle
I'll just jump right into it. I have a model called Request which I
I am trying to print the last 200 or so lines from Android Logcat

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.