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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:08:50+00:00 2026-06-18T00:08:50+00:00

Is it just me or is it a global RSpec behavior that when I

  • 0

Is it just me or is it a global RSpec behavior that when I name my rails model scope :public, initialize object from this model, and stub this object Rspec fails

class DocumentName < ActiveRecord::Base

  scope :public,    lambda{where( public: true) }  #line 3
end

nothing special, Rails application works

DocumentName.public  # => [ #DN, #DN, #DN... ]
# SELECT `document_names`.* FROM `document_names` WHERE `document_names`.`public` = 1

however RSpec fails

describe DocumentName do
  let(:resource){DocumentName.new}  
  it do
     resource.stub(:name).and_return('foo')   #line 16
     resource.save.should be true
  end
end

 Failure/Error: resource.stub(:name).and_return('foo')
 ArgumentError:
   wrong number of arguments (1 for 0)
 # ./app/models/document_name.rb:3:in `block in <class:DocumentName>'
 # ./spec/models/document_name_spec.rb:16:in `block (2 levels) in <top (required)>'

…and funniest thing, I’m not doing anything with that scope in this scenario.

However if I name this scope something else than :public e.g: :are_public:

class DocumentName < ActiveRecord::Base
  scope :are_public,    lambda{where( public: true) }
end

…everything pass O_O

Rails 3.2.11 (but same thing on any 3.2.x)
Ruby ruby-2.0.0-rc1 ( but same for any ruby-1.9.3) 
rspec-core (2.12.2)
rspec-expectations (2.12.1)
rspec-mocks (2.12.1)
rspec-rails (2.12.2)
  • 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-18T00:08:51+00:00Added an answer on June 18, 2026 at 12:08 am

    private and public are Ruby’s access modifiers:

    class User
      private
      def some_private_method
      end
    
      public
      def some_public_method
      end
    end
    

    While they may seem like keywords, they are actually method calls. It’s not really a good idea to overwrite them.

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

Sidebar

Related Questions

Just see this: SELECT clientid,clientname,startdate,enddate,age FROM clients WHERE clientid IN (1,2,3,4,5) AND CASE WHEN
I just create a Global Variable in Ms. Dynamic Nav 2009 R2 and I
I've just read all of objective-c global constants variables Q&A but I found them
just wanted to ask where I define initial class properties? From other languages I
Just learning the world of jquery, and all my googling gives examples like this:
I want to implement the concept of a Workspace. This is a global concept
I have classes like this one: class SomeObject { public function __construct($param1, $param2) {
I have a captcha in my MVC application that is called from a HttpHandler
For the downvote fairies.. I know that php is the wrong language for this...
What is the recommended way to get a handle to the global object in

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.