Skip to main content

All Questions

0 votes
1 answer
36 views

Can the rails testing environment respond to http requests?

I have a nodejs pupeteer script that does client http calls to the rails server to produce PDF files of the web page the rails server generate. The rails server later processes those PDF files for ...
Julien Lamarche's user avatar
0 votes
2 answers
45 views

In Ruby on Rails tests, how do I call from a ControllerTest a method defined inside a Controller

I have a test class called AdControllerTest, which I am using to test AdController. From AdControllerTest, I'm trying to call a method defined in AdController, but I don't think I'm doing it right and ...
itsmarziparzi's user avatar
1 vote
1 answer
134 views

How should I write tests for a Controller that returns a nondeterministic result for a GET request

Let me present my problem into the simplest example I can come up with that is somewhat similar. I have a database table "Article" with an integer attribute named "weight" and a ...
itsmarziparzi's user avatar
0 votes
1 answer
88 views

Can't pass images as params in Rspec Rails controller spec

Trying to test the create action in post_controller. All other controllers' create actions work just fine. After some debugging, the error seems to be the params. The images passed from the post ...
Usman Ahmed's user avatar
0 votes
1 answer
93 views

How to test conditional redirection in controller method with RSpec

I have that method in my controller def promotional_sales redirect_to plans_path and return unless promotional_campaign_active? config_meta_tags({}, { title: "Subscription ...
Rodrigo Almeida's user avatar
2 votes
1 answer
48 views

How can I detect the timing when I have to change a method in rspec?

Suppose I have the following code. class Answer enum type: %i[text checkbox image] def round_type case answer.type when text, checkbox :text when image :multimedia ...
squidlaw's user avatar
0 votes
1 answer
138 views

Rails Test Expects NIL

So I am writing a unit test to test whether a contact is blocked... if it is blocked then I expect the contact to be unable to send a message. Here is backend logic I am trying to test if account ...
kahuria00's user avatar
  • 357
0 votes
1 answer
2k views

test update request with RSpec failed

I have two problems when I try to test the update action with RSpec, here is the controller file: #volunteers_controller.rb module Api module V1 class VolunteersController < ...
Yingqi's user avatar
  • 1,335
1 vote
1 answer
114 views

How to test composite Rails model scopes?

Consider the following model: class Model < ActiveRecord::Base scope :a, -> () { where(a: 1) } scope :b, -> () { where(b: 1) } scope :a_or_b, -> () { a.or(b) } end now ...
pudiva's user avatar
  • 274
1 vote
1 answer
542 views

Ruby on Rails test fails or succeeds depending on how the test suite is called

I'm working my way through the Hartl Ruby on Rails Tutorial (4th Edition) and I've come across a problem with some tests I'm trying to run - specifically the exercise in section 11.2.3. All of my ...
piersb's user avatar
  • 599
3 votes
4 answers
4k views

How do I test an instance variable in a controller?

A couple of my mentors have told me to test a piece of code with controller spec even though the contents are being tested by some request specs. I am wondering if I can test whether an instance ...
airvine's user avatar
  • 700
1 vote
2 answers
106 views

Testing methods of class when instantiation creates HTTP request

I have some tests for an object that look like as follows: let(:bot) { MyObject.new('/some/config/file.json') } The problem is, the very act of instantiating MyObject creates an HTTP request. The ...
john's user avatar
  • 11
0 votes
1 answer
790 views

How to cleanly stub out REST client when in test environment

I have a basic model like the following class MyModel def initialize(attrs) @attrs = attrs @rest_client = Some::REST::Client.new end def do_a_rest_call(some_str) ...
randombits's user avatar
1 vote
0 answers
33 views

Call by name parametrized tests in rails

In rails project I have the following test: [1,2,3,4,5].each do |i| test "mypow2 #{i}" do assert mypow2(i) == i*i end end if the test is not parametrized I can run it by: rails test path/to/...
Jeni's user avatar
  • 1,088
0 votes
2 answers
530 views

Validation tests in Ruby on Rails always false

I am writing some unit tests in Ruby on Rails. Even when I expect the test to have an outcome that passes the validation, the test fails. Here is my model that I am testing: class Post < ...
Goose9192's user avatar
  • 109

15 30 50 per page
1
2 3 4 5
13