rack-test

Can I test that a Sinatra post method successfully saves to a YAML store?

人盡茶涼 提交于 2019-12-11 04:13:23
问题 I can't find a basic explanation anywhere about how I can test, with Rack::Test, that a Ruby/Sinatra post method successfully saves data to a YAML store/file. (This explains testing get , which I can do(!), but not post ; other mentions of testing post methods with rack/test seem irrelevant.) For self-study, I'm building a "to do" app in Ruby/Sinatra and I'm trying to use TDD everything and unit test like a good little boy. A requirement I have is: When a user posts a new task, it is saved in

Testing an AJAX POST using Rack::Test - how to pass in data?

匆匆过客 提交于 2019-12-10 21:30:27
问题 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', { username: 'test_reg', password: 'test_pass', email: 'test@testreg.co' }.to_json, {"CONTENT_TYPE" => 'application/json', "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} last_response.must_be :ok? last_response.body.must_match 'test_reg has been saved' end end But at

How to iterate through an in-memory zip file in Ruby

蓝咒 提交于 2019-12-08 15:24:47
问题 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 last_response.body . I have looked through the documentation of RubyZip but it seems that it's always expecting a file. Since I'm running a unit test, I prefer to have everything done in the memory as not to pollute any folder with test zip files,

Rack test fails: No response yet for JSON request

╄→гoц情女王★ 提交于 2019-12-07 11:52:42
问题 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 # Reduced to the minimum code. require "spec_helper" include ApiHelper # not sure if I need this describe "/api/v1/farms", type: :api do context "farms viewable by this user" do let(:url) { "/api/v1/farms" } it "json" do get "#{url}.json" assert last