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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:06:02+00:00 2026-06-05T09:06:02+00:00

I have a method: require ‘openssl’ def extract_creds(data) pfx = OpenSSL::PKCS12.new(data) { :certificate =>

  • 0

I have a method:

require 'openssl'

def extract_creds(data)
  pfx = OpenSSL::PKCS12.new(data)

  { :certificate => pfx.certificate.to_pem, :key => pfx.key.to_pem }
rescue
  # handle error
end

and i want to write a rspec example for it. How should i properly mock pfx object?

  • 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-05T09:06:04+00:00Added an answer on June 5, 2026 at 9:06 am

    Why this may be the wrong question

    You should generally use a mock when you want to:

    1. Avoid testing system behavior outside the unit under test.
    2. Avoid expensive operations, such inter-system tests.
    3. Ensure that an object is called, but you don’t care about the results.

    In this case, it’s not clear why you want to test this behavior, or what you expect the results to be, or why you think you might not get it. For the most part, testing a well-tested external library is not the right thing to do.

    What I think the right question is

    So, depending on what you really want to test, you may want to check:

    1. Whether the method raises any exceptions.
    2. Whether your method is actually called from some object that should call it.

    In both cases, though, there seems to be no real benefit to mocking the library vs. including a real certificate as fixture data. Fixtures are better than mocks for actually exercising code.

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

Sidebar

Related Questions

I have a method that has some data objects passed into it, does some
If I have a config.ru file like this: def my_method 1+2 end require 'my_sinatra_app'
I have a public method that uses a local private method to get data
I currently have this working but it requires me to have a static method
I have a class that requires a specific method to be called before being
I have method in a class that I need to make sure is only
I've got some 3rd party beans that have method signatures that fit quite well
I create small application which is media player. I have method where I have
I have a method that accepts an IEnumerable-decimals and performance various math functions. I
i have a method which takes in a DotNetOpenAuth (formally known as DotNetOpenId) Response

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.