18,276 questions
2
votes
1
answer
63
views
Stub a method on a Thor CLI
I have a Thor class that has a getter method defined like this:
# Playgrounds CLI skeleton class.
# Commands are added from commands folder
class CLI < Thor
def self.exit_on_failure?
true
...
1
vote
1
answer
87
views
How does a GitHub Actions workflow notice that a unit test has failed?
Finished in 0.0137 seconds (files took 0.0769 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/basic_math_spec.rb:10 # Basic-Math Subtract numbers
Error: Process completed with ...
1
vote
1
answer
64
views
How to sign in a user and create associated records with factories when testing
I have several tables in my application which are associated with a user. In order to run my integration tests the application first needs to log in the test user.
config.before(:each, :type => ...
0
votes
1
answer
26
views
Set action_mailer.default_url_options and routes.default_url_options in Rails test environment
I've seen a lot of questions about errors concerning action_mailer.default_url_options and default_url_options[:host] during system tests.
Below I share a good solution I found.
1
vote
0
answers
45
views
Caypbara/rspec throwing both `Capybara::ModalNotFound` and `Selenium::WebDriver::Error::UnexpectedAlertOpenError` in the same test
So i have a "Delete" link that brings up a html confirm modal. In my rspec system test though, it keeps erroring out with both errror messages Capybara::ModalNotFound and Selenium::WebDriver:...
0
votes
1
answer
46
views
New method of Rails controller being called by Rspec test
I have a Rails controller I'm trying to write a new method for, and I'm running into an issue writing the tests for it. I've simplified the methods and tests repeatedly just trying to get something to ...
1
vote
0
answers
98
views
RSpec system specs fail without allowing JS to finish
I'm having an issue running my RSpec suite. The suite is "old," and everything worked fine until a few days ago when system specs started to fail without an apparent reason.
All the failures ...
0
votes
1
answer
50
views
Rspec: testing "rescue_from" on type: :request
I have a Rails 6.1 controller that sets:
# File: app/controllers/foo_controller.rb
rescue_from Exception, with: :error_handler
My Rspec 6.1 test (is a "request" type) is like:
# File: spec/...
0
votes
1
answer
181
views
Rspec - How to replace receive by have_received when dealing with an expect within a block?
I have the following Ruby class I want to test:
class Logger
# ...
def process
X.process
rescue StandardError => e
::Rails.logger.error('Progname') { 'Could not produce the audit log'...
1
vote
2
answers
96
views
Rails acceptance validation always correct
I have this Rails 6.1 model:
class BankAccount < ApplicationRecord
belongs_to :donor
before_validation -> {
puts #AccAuth: #{account_authorization}"
}
validates :...
-1
votes
1
answer
93
views
What is alternative of `stripe-ruby-mock` to test the latest (v15) Stripe API?
Currently, we are using the stripe-ruby-mock gem in our application for testing Stripe APIs Integration, along with Stripe version '2015-04-07'. As we proceed with the Stripe upgrade and aim to ...
1
vote
0
answers
61
views
Devise gem error in test environment: serialize_from_session gives error "wrong number of arguments (given 10, expected 2)"
I just updated my app to rails 8 with the newest version of Devise and hotwire turbo. When running tests with Capybara/Rspec I'm seeing certain form submissions fail with a 500 error from inside of ...
1
vote
1
answer
132
views
Rspec - Uniqueness shouldamatcher failing
I have an ActiveRecord table with a column called name. I need this field to be present and unique. So I have the following specs
it { should validate_presence_of(:name) }
it { should ...
0
votes
1
answer
167
views
Deprecation Warning: "Bolding log text with a positional boolean is deprecated" when running Rails tests with Rspec
When running my tests in a Rails application, I see the following deprecation warning multiple times:
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed ...
1
vote
1
answer
76
views
How to test a method call with keyword arguments not including a particular keyword
I have the following method:
def clone(branch: nil, depth: nil)
...
end
For a particular test case, I want to test that the method is called without the branch argument. In Ruby 2.x the following ...
0
votes
0
answers
87
views
Expect method not to be called by default
Let's say there's a method report defined on ErrorReporter module.
In my RSpec test suite I'd like to somehow globally stub this method so that test fails if it's not explicitly expected to receive ...
-1
votes
2
answers
470
views
How do I install factory_bot_rails? I am using Rspec
I am trying to install factory_bot_rails to use with rspec.
I am working my way through Everyday Rails Testing with RSpec A practical approach to test-driven development, by Aaron Sumner, http://...
1
vote
0
answers
72
views
API test fails but works fine with GraphiQL route (Header issue?)
I'm working on a Rails API with GraphQL, and I'm having issues with testing a mutation using RSpec. When I use the /graphiql route and provide the required headers manually, everything works perfectly....
0
votes
0
answers
51
views
Rspec system test for mobile using responsive web layout - how to specify width lower than 500px using chromedriver?
I'm trying to write an RSpec system spec to test working functionality through a responsive web layout that could emulate how one would use things in a mobile.
How do I get the window size to have a ...
0
votes
1
answer
127
views
Error using Selenium WebDriver and Capybara in Rails application
I'm using rails 6.1 with ruby 2.6.5 and I’m creating tests for an Active Admin new page, The best way I found to test this new page was by using the gems Capybara, Webdrivers, and Selenium-Webdrivers. ...
1
vote
0
answers
74
views
RSpec expect(...).to receive(...).with(...) return error unexpected arguments with same variables
class Foo
def fizz(user)
puts user
end
end
let(:user){create(:user)}
it do
expect(Foo).to receive(:fizz).with(user)
end
I run this test in RSpec of Rails app. Test fails with below ...
1
vote
0
answers
21
views
My Rspec Test Isn't Following The Range I Specified?
I'm running into trouble with my test. Here it is. It performs a number of inserts into a C database db. The problem is that my test doesn't seem to actually do the number of inserts.
If I specify the ...
1
vote
3
answers
103
views
ISO 8061 built-in support in RSpec or Minitest
When to_json is called on an object in Rails, the datetime objects are converted to the ISO 8601 standard automatically which is an excellent tool for sending data back to a client.
[43] pry(main)> ...
0
votes
1
answer
96
views
When do raise_errors_for_deprecations! and raise_on_warning trigger?
Ruby: 3.4.0-preview1
rspec: 3.13.0
.rspec
--warning
spec_helper.rb
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'rspec/its'
RSpec.configure do |config|
config....
0
votes
1
answer
82
views
How to test active storage dimension validation?
I have installed this gem to validate and test active storage:
gem 'active_storage_validations'
# Asset Model
class Asset < ApplicationRecord
has_one_attached :portrait
validates(
:...