Questions tagged [rack-test]
46 questions
14
votes
8 answers
How to iterate through an in-memory zip file in Ruby
I am writing a unit test, and one of them is returning a zip file and I want to check the content of this zip file, grab some values from it, and pass the values to the next tests.
I'm using Rack Test, so I know the content of my zip file is inside…

garbagecollector
- 3,731
- 5
- 32
- 44
7
votes
2 answers
nil response object in Rails 5.2, RSpec-Rails 3.7 spec for GET request
I've been heads down in this and feel like I'm probably making a simple mistake, but I haven't been able to find any information on this problem.
I have some request specs for Rails 5 and, when I test for a redirect--but not for a rendered…

Dana Scheider
- 389
- 3
- 15
5
votes
2 answers
How do I get the Sinatra app instance that's being tested by rack-test?
I want to get hold of the app instance being tested by rack-test so that I can mock some of its methods. I thought I could simply save the app instance in the app method, but for some strange reason that doesn't work. It seems like rack-test simply…

Hubro
- 56,214
- 69
- 228
- 381
5
votes
2 answers
Sinatra unit test - post with JSON body
I am trying to build a unit test for a REST API I built using Sinatra. For right now I just want to test that my echo function works right. Echo uses POST and will return the exact same payload from the post. I am still new with ruby, so forgive…

user2718753
- 51
- 1
- 2
4
votes
1 answer
How to distinguish between the Sinatra request object and the Rack Test request method?
I have a method that runs in the Sinatra app scope that checks to see if the request is secure:
secure_request?
request.env[ 'HTTPS' ] == 'on'
end
This works fine, but when I call it from another class that does not share the Sinatra app scope,…

B Seven
- 44,484
- 66
- 240
- 385
3
votes
2 answers
How to send custom header with rack::test?
I spent about two days without success trying to send custom headers with Rack::Test. I just can't send any header into my app.
I found a lot of examples in the net with the similar code -- method( address, body, headers ), but for me they don't…

Dimitri
- 623
- 7
- 14
3
votes
1 answer
Testing for session variables using Rack::Test using RSpec
Given the code
env "rack.session", {:var => 'value'}
I can set a session variable in rack-test. However, how can I (using rack-test) test for said session variable in RSpec? Hypothetically, for example:
expect(env['rack.session'][:var]).to…

VULPINE
- 31
- 3
3
votes
0 answers
How can I get Sinatra to generate testrunner-friendly error pages?
I'm testing a Sinatra app with several of the usual suspects (rspec, rack/test). From time to time during development, an error within the application will cause Sinatra to generate an error response page. This page is a gorgeous bit of HTML and…
user240438
3
votes
1 answer
testing padrino post methods are stopped by csrf
I have a padrino controller with a single post method and a single get method. I can use rack-test to test the get method but not the post method. When I am testing the request returns 403. I think this is because of padrino's built in csrf…

Peter Saxton
- 4,466
- 5
- 33
- 51
3
votes
2 answers
Testing an AJAX POST using Rack::Test - how to pass in data?
I'm using Rack::Test to test my app and need to test the posting of data via AJAX.
My test looks like:
describe 'POST /user/' do
include Rack::Test::Methods
it 'must allow user registration with valid information' do
post '/user', {
…

Dave Sag
- 13,266
- 14
- 86
- 134
3
votes
1 answer
Rack test fails: No response yet for JSON request
I am trying to create a JSON API for my Ruby project following the Ticketee example provided in Yehuda Katz's book Rails 3 in Action, chapter 13. Here is an RSpec test described on page 353 adapted to my environment.
# /spec/api/v1/farms_spec.rb #…

JJD
- 50,076
- 60
- 203
- 339
3
votes
2 answers
How to refactor RSpec tests for API
I've got a series of RSpec tests for a Sinatra based API, and would like to refactor them to make them a little simpler and reduce repetition.
Here's an example a test for a route:
describe 'post /sections with empty data' do
before do
…

djlumley
- 2,955
- 2
- 24
- 30
2
votes
1 answer
Why is an Array in my payload being flattened in Sinatra / Rack::Test?
I'm trying to test a small Sinatra app using rspec. I want to pass a rather complex payload and am running into issues i do not understand: my payload contains an array of hashes. When I run the actual application this will work as expected, yet…

m90
- 11,434
- 13
- 62
- 112
2
votes
0 answers
RSpec, Rack/Test, Sinatra message expectation always passes even though an error gets thrown
Testing a whitelisting operation via the given the test:
require 'spec_helper'
describe '/orders' do
describe 'POST /order' do
it 'whitelists attributes' do
expect_any_instance_of(Logger).to_not receive(:warn)
order = {
…

daino3
- 4,386
- 37
- 48
2
votes
3 answers
Is there an easy way to include RackTest methods in Capybara tests?
Capybara 2 removed these and suggests to separate them, but we have some situations where we'd like to use both in a test (enabling an api key through the view, then hitting the api, etc).
I tried including include ::Rack::Test::Methods but I'm…

Brian Armstrong
- 19,707
- 17
- 115
- 144