Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run with `rspec action_controller_gem.rb`. Fails as it is, but works with https://github.com/rspec/rspec-rails/pull/1568 applied.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.0.0.beta3'
gem 'rspec-rails', '3.5.0.beta1'
gem 'rails-controller-testing', '0.1.1'
end
require 'rspec-rails'
require 'action_controller/railtie'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get '/' => 'test#preview'
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def show
end
def preview
prepend_view_path(MyResolver.new)
render action: :show
end
class MyResolver < ActionView::Resolver
def find_all(*args)
find_templates(*args)
end
def find_all_anywhere(*args)
find_templates(*args)
end
private
def find_templates(name, prefix = nil, partial = false, details = {}, key = nil, locals = [])
name.prepend("_") if partial
path = [prefix, name].compact.join("/")
template = find_template(name, path)
[template]
end
def find_template(name, path)
ActionView::Template.new(
"",
name,
->(_template) { %("") },
virtual_path: path,
format: :html
)
end
end
end
# ========================
require 'rspec/rails'
RSpec.describe TestController, type: :controller do
it "GET #preview renders the show action" do
get :preview
expect(response).to render_template(:show)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.