Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
21 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 ...
mrateb's user avatar
  • 2,557
0 votes
0 answers
3 views

FactoryBot - Test without creating associated factories

I'm working on a feature that I need to test. To test the feature I need to create an instance of my Build model. Usually this should not be a problem. My problem here is that Build has relations to ...
mrateb's user avatar
  • 2,557
0 votes
0 answers
43 views

Failure/Error: choice = gets.chomp.upcase NoMethodError: undefined method `chomp' for nil [closed]

I have little experience in ruby development and I can't understand why this error occurs when running tests. Can you help me? class CashMachine START_BALANCE = 100.0 def initialize @balance =...
kickrich's user avatar
0 votes
1 answer
22 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 ...
Samuel Da Costa's user avatar
0 votes
1 answer
67 views

Is there a way to set up an expectation for a hash but being "indifferent" about whether keys are symbols or strings?

Working with rspec-expectations 3.13.3 and have code such as: def methname(**kwargs) # let's assume this method doesn't mind whether the kwargs are keyed by symbols or strings p(received: kwargs) ...
Tim Diggins's user avatar
  • 4,506
1 vote
1 answer
42 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 ...
Sergio's user avatar
  • 272
0 votes
3 answers
59 views

In RSpec, how to mock a method so that it returns its argument

Let's say I have a class with a method that modifies and returns a hash. When testing the class the method will be called, but for the purposes of the test, I want it to return its argument ...
dB''s user avatar
  • 8,280
0 votes
0 answers
48 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 ...
vetements's user avatar
0 votes
2 answers
92 views

Rails - Named route not working in controller spec

In my routes.rb file I had this route: resources :profiles In my controller specs I had thus paths such as: profiles_path new_profile_path etc. Now I had to move this inside a namespace. The new ...
mrateb's user avatar
  • 2,557
-1 votes
2 answers
83 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://...
Jennifer James's user avatar
1 vote
2 answers
59 views

Testing valid factory when belongs_to

In my Rails application I have a model Profile that belongs_to a User as such: class User < ApplicationRecord has_many :profiles end class Profile < ApplicationRecord belongs_to :user ...
mrateb's user avatar
  • 2,557
1 vote
0 answers
59 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....
José Sávio's user avatar
0 votes
3 answers
49 views

Simplecov wants me to test controller assignments, is there a way to do this without the rails-controller-testing gem?

For a very basic controller action such as: def new @user = User.new end Simplecov wants this assignment tested. I can't think of anyway to test it other than using the rails-controller-testing gem ...
Chad's user avatar
  • 768
0 votes
0 answers
34 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 ...
boddhisattva's user avatar
  • 7,360
-2 votes
1 answer
41 views

Testing Active Admin Page with RSpec

In my Rails application, ruby 2.6.5, rails 6.1. I use Active admin and I created this page. How can I create some tests for this using rspec? I have already created tests for the model and the ...
Karina Piloupas's user avatar
0 votes
1 answer
46 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. ...
Rodrigo Almeida's user avatar
1 vote
2 answers
134 views

GET request JSON body params in rswag specs

Issue How can I write a rswag spec that would pass my_field: 'my_value' into my controller's params for a GET request? Initial attempt config/routes.rb: Rails.application.routes.draw do namespace :...
Augustinas's user avatar
0 votes
0 answers
47 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 ...
nrmn0006's user avatar
0 votes
1 answer
55 views

RSpec error with expecting DateTime value to be_within a duration of a ActiveSupport::TimeWithZone value

Why does the following test give me a TypeError: expected numeric error: it { expect(DateTime.now).to be_within(1.second).of Time.zone.now } but this test does not? it { expect(DateTime.now).to ...
aarona's user avatar
  • 37.2k
1 vote
0 answers
18 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 ...
Eugene's user avatar
  • 11
0 votes
0 answers
90 views

How to run RSpec system specs with Dev Containers

I'm trying to set up DevContainers with a Rails 7.2 app, but I'm having difficulties getting my RSpec system specs to run correctly. My compose.yaml file includes the selenium/standalone-chromium ...
Sig's user avatar
  • 5,924
0 votes
0 answers
79 views

CircleCI Parallelism messing up with time-based tests

We have a big old build that is taking too long to run tests and Im trying to setup parallelism to speed things up. After the configuration, I can see the tests are indeed running in parallel and are ...
João Menighin's user avatar
1 vote
3 answers
82 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)> ...
Arslan Ali's user avatar
  • 17.8k
2 votes
2 answers
75 views

RSwag not supporting apiKey pairs in requests

As you can see from the github issue, RSwag does not support multiple headers for api Key authentication. This is my openapi/swagger yml, in following with Multiple API Key Setup in swagger docs: ...
Ben G's user avatar
  • 26.7k
0 votes
0 answers
18 views

Rspec Command Not Being Recognized?

I installed Rspec with gem install rspec but Rspec was apparently not being recognized. I'm not sure why. I've been trying to get rpsec to work for the past couple of days. I'm not using a bundle. I'm ...
Eugene's user avatar
  • 11
0 votes
1 answer
42 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....
0lli.rocks's user avatar
  • 1,072
0 votes
0 answers
63 views

binding.pry is often ignored since upgrading to ruby 3.3 + rails 7

I am currently in the process of upgrading my rails 6 app to 7, and when I've run into issues, I have been trying to debug, and keep running into this weird issue where binding.pry does not seem to be ...
patrick's user avatar
  • 9,690
0 votes
1 answer
64 views

Why do Active Storage tests hang?

I have installed this gem to validate and test active storage: gem 'active_storage_validations' gem 'shoulda-matchers', '~> 6.0' # app/models/asset.rb class Asset < ApplicationRecord ...
Chiara Ani's user avatar
  • 1,073
0 votes
1 answer
58 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( :...
Chiara Ani's user avatar
  • 1,073
1 vote
1 answer
55 views

Ruby rspec expectations: Is there any way to ensure a keyword expectation is not "bogus"?

Let's say I have: class Foo def do_thing(arg_one:, arg_two:) # ... end end class Bar def initialize(foo) @foo = foo end def do_delegated_thing @foo.do_thing(arg_one: "x&...
aarestad's user avatar
  • 607
0 votes
1 answer
78 views

Capybara does not visit routes inside rails 7.2 application

I have always used Capybara with Rspec and with Rails 4, 5, and 6 - inside Docker containers without Selenium - to run end-to-end tests. Now, with Rails 7.2, the same tests fail because Capybara, ...
Nellinux's user avatar
1 vote
2 answers
88 views

Passing information from 'before' to 'after' block

(I'm using JRuby, but I think that my problem applies to MRI Ruby as well) My RSpec definition has this overall structure: RSpec.describe 'XXX' do before(:all) do # preparation common for each ...
user1934428's user avatar
  • 22.1k
0 votes
1 answer
112 views

Sidekiq::Testing.fake! and retrying jobs

I'm writing a test that invokes Sidekiq::Testing.fake!. The test is designed to assert behavior that occurs when a particular job raises an error. Normally, the job is supposed to retry up to 5 times ...
Argus9's user avatar
  • 1,925
0 votes
0 answers
40 views

Making JS specs work with headless Chrome

I have a Sinatra app with a Rspec suite and now I need to run it on GitHub Actions. My workflow looks like: name: continuous-integration on: pull_request: branches: - '*' push: ...
Sig's user avatar
  • 5,924
0 votes
2 answers
75 views

Rails: Accessing SQL alias attributes declared with ".select"

Let's say in my controller, I use a "where" clause on Teachers so I can put the alias, class_size, on the number of students @teachers = Teachers.select("teachers.*, count(students.id) ...
cheetoriko's user avatar
3 votes
2 answers
437 views

How to skip "Choose search engine" with capybara/selenium/chrome [duplicate]

When I open Chrome from capybara I get this screen: here is the image on imgur because stack overflow images don't work for me: https://i.imgur.com/UE9teHL.png That results in errors in my specs, how ...
Dorian's user avatar
  • 8,945
3 votes
1 answer
156 views

RSpec Chrome Webdriver tests fails on RSpec::Core::MultipleExceptionError: no such window - invalid argument: 'handle' must be a string

So without any good reason my Rails 7.2 RSpec system test that run on headless Chrome Selenium Webdriver started to fail on error RSpec::Core::MultipleExceptionError: no such window (Session info: ...
equivalent8's user avatar
  • 14.2k
0 votes
1 answer
81 views

Writing a spec that involves Signal Trap and Process.kill - Only fails in CI?

I am struggling with writing specs for this implementation, which runs fine in my local env. My theory is that since the spec has Process.kill instructions the github CI action job that runs this spec ...
queroga_vqz's user avatar
  • 1,039
0 votes
1 answer
35 views

Rspec expect to receive not acknoledging a call

I am trying to check a service is called in a test. Here is the error message : (#<Payments::CardPaymentProvider:0x00007f3ee3a172e0>).debit(*(any args)) expected: 1 time with any ...
Syl's user avatar
  • 3,829
0 votes
2 answers
157 views

problem installing Rspec with factory_bot. Factories are not registered

I am using rails 7.1.3.4 with rspec-rails 6.1.3 and factory bot. I have added require 'factory_bot_rails' and config.include FactoryBot::Syntax::Methods in spec/spec_helper.rb Here is my factory in ...
Syl's user avatar
  • 3,829
0 votes
1 answer
54 views

In Rspec, how can I set a login token (http header) in every test without having to pass it as an argument to every http request

I'm writing an integration for an API that requires an authentication header. But authentication is not part of the test itself, and I would like to avoid setting the header in every single get/post I ...
Andre driem's user avatar
0 votes
0 answers
90 views

ERROR -- : Can't add attachment, no test, step or fixture is running (allure-rspec)

I'm integrating allure reports with my API test project using Rspec. I wanted to attach request and response details to the report after each testcase. The following is my response_parser to get ...
Mona101ma's user avatar
  • 772
1 vote
1 answer
162 views

Can I write one expectation in RSpec which demands a method is called only once with specific arguments?

I'm just finishing my first year writing production code in Rails, and I'm not really stuck here, but the non-rubyness of what I'm experiencing is weird, and I wanted to see if anyone had this problem....
Louis Pate's user avatar
0 votes
1 answer
39 views

How can I rearrange my test to allow me to access the referral

I have a simple request spec and am trying to test that :notify_referrer is called. def create @referral = Referral.new(referral_params) if @referral.save @referral.notify_referrer ...
Jeremy Thomas's user avatar
1 vote
3 answers
81 views

Testing the contents of an array inside a hash

In Rspec I am testing a hash that contains an array like this: subject { described_class.call(build: build_one, user:) it 'returns the correct data' do response = subject expected_response = { ...
BluePrint's user avatar
  • 2,124
0 votes
0 answers
66 views

Stubbing requests in ActiveJob for jobs enqueued by other jobs using Rails, Rspec, and WebMock

I'm writing tests for a Job in my Rails app. When the Job receives over 500 messages, it enqueues other jobs to handle the messages. When it receives less than 500 messages, it handles the messages ...
Sebastian Scholl's user avatar
0 votes
0 answers
95 views

Using test_prof before_all recipe with manual connection switching in multiple db setup

I am using test-prof gem with before_all recipe to create all the necessary records for the suite and run a heavy service afterwards. Yet I'm running into a problem when a block of queries is executed ...
potashin's user avatar
  • 44.6k
0 votes
3 answers
114 views

How to prevent password from being updated if empty in Rails Model and test it with RSpec?

I use Bcrypt gem for password encryption. User model: class User < ApplicationRecord has_secure_password validates :password, presence: true, length: { minimum: 6 }, confirmation: true # ... ...
Chiara Ani's user avatar
  • 1,073
0 votes
1 answer
59 views

Why does RSpec Rails generate mailer fixtures?

I executed this command: rails g mailer users/confirmations confirm_email It generated this file at spec/fixtures/users/confirmations/confirm_email: Users::Confirmations#confirm_email Hi, find me in ...
Chiara Ani's user avatar
  • 1,073
0 votes
0 answers
154 views

Rspec expectation error: reading hash argument as keyword arguments

I'm in the middle of an update to Rails 7.1.3 and I've run into an interesting issue. I have an initialize which has one positional argument (which defaults to an empty hash) and some keyword ...
AJFaraday's user avatar
  • 2,440

1
2 3 4 5
366