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

  • Home
  • SEARCH
  • 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 9145691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:34:39+00:00 2026-06-17T10:34:39+00:00

How would you test this method with rspec? def schema @schema ||= Schema.new(owner, schedules,

  • 0

How would you test this method with rspec?

def schema
  @schema ||= Schema.new(owner, schedules, hour_interval)
end
  • 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-17T10:34:40+00:00Added an answer on June 17, 2026 at 10:34 am

    If felt inclined to ask “and what did you try to test it”, but here’s my answer anyway: If you’re unit testing in rspec, and you define methods to be your units, I would suggest to test it like this:

    describe "schema" do
      let(:owner) { mock('owner') }
      let(:schedules) { mock('schedules') }
      let(:hour_interval) { mock('hour_interval') }
      let(:schema) { mock('schema') }
      before(:each) do
        subject.stub! :owner => owner, :schedules => schedules, :hour_interval => hour_interval
      end
      context "unmemoized" do
        it "should instantiate a new schema" do
          Schema.should_receive(:new).with(owner, schedules, hour_interval).and_return schema
          subject.schema.should == schema
        end
      end
      context "memoized" do
        it "should use the instantiated and memoized schema" do
          Schema.should_receive(:new).with(owner, schedules, hour_interval).once.and_return schema
          2.times do
            subject.schema.should == schema
          end
        end
      end
    end
    

    Like this, you test the unit and all it does in isolation.

    For explanation regarding the details, look at The RSpec Documentation and/or Best RSpec Practices

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

Sidebar

Related Questions

So I have installed pymox and I would like to test this method: class
We are running a test automation suite and would like to prevent this message
Can anyone tell me why this code would not be working? $('body').on('test', function() {
This is an example XML file that would come from the Android Client. <test>
I have this: $(document).ready(function() { $(input[type=button]).click(function () { $(#test).html(W3Schools); alert(Would submit: + $(this).siblings(input[type=text]).val()); $.ajax({
Say I have a vector: (def data [Hello World Test This]) And I want
Lets say I define class with method like this: class Test { public function
How would I write a method to be used in rspec testing to access
I'm adding more rspec testing to my app and would like to test a
I would love to be able to test java code with rspec under jruby,

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.