If you like me tried to merry the two, you probably noticed they didn’t like each other. Here’s a small hack to let you test your Metal controllers. For RSpec to work with such controller, we need the following modules:
Now, to test it you need to include all other important modules before the tests, like this (I put it inside the spec file). Here’s my sample api_controller_spec.rb file:
123456789101112131415
require'spec_helper'classApiControllerincludeActionController::UrlForincludeActionController::TestingincludeRails.application.routes.url_helpersincludeActionController::CompatibilityenddescribeApiControllerdoit"should return content from 'work'"doget:workresponse.body.should=={:data=>1}.to_jsonendend