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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:19+00:00 2026-05-25T11:37:19+00:00

Say I have an instance method that does many different things that I need

  • 0

Say I have an instance method that does many different things that I need to test, something like store#process_order. I’d like to test that it sends an email to the customer, adds an entry in the orders table, charges a credit card, etc. What’s the best way to set this up in rspec? Currently, I’m using rspec and factory girl I do something like this:

describe Store do
  describe "#process_order" do
    before do
      @store = Factory(:store)
      @order = Factory(:order)
      # call the process method
      @store.process_order(@order)
    end

    it 'sends customer an email' do
      ...
    end
    it 'inserts order to db' do
      ...
    end
    it 'charges credit card' do
      ...
    end
  end
end

But it feels really tedious. Is this really the right way to write a spec for a method that I need to make sure does several different things?

Note: I’m not interested in answers about whether or not this is good design. It’s just an example I made up to help w/ my question – how to write these types of specs.

  • 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-25T11:37:20+00:00Added an answer on May 25, 2026 at 11:37 am

    I think what you are doing is fine and I think it’s the way rspec is intended to be used. Every statement (specification) about your app gets its own block.

    You might consider using before (:all) do so that the order only has to get processed once but this can introduce dependencies on the order the specs are run.

    You could combine all the code inside describe "#process_order" into one big it block if you wanted to, but then it would be less readable and rspec would give you less useful error messages when a spec fails. Go head and add raise to one of your tests and see what a nice error message you can get from rspec if you do it the way you are currently doing it.

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

Sidebar

Related Questions

For instance, let's say I have a User model. Users have things like logins,
In C#, suppose you have an object (say, myObject ) that is an instance
Let's say that I have a bunch of class instances that serve different purposes,
First I would like to say that I have only worked with java for
So I have a a text file that looks something like this: public >ret
Let's say I have a MyObject instance which is not initialized: var a:MyObject =
Let's say we have a class foo which has a private instance variable bar
Let's say I have a class Foo with some primitive instance variables. I initialize
Say, for instance, I have a class: public class MyFoo : IMyBar { ...
Let's say I have two database instances: InstanceA - Production server InstanceB - Test

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.