Skip to content

Instantly share code, notes, and snippets.

@the-undefined
Last active January 20, 2016 15:27
Show Gist options
  • Save the-undefined/fd45a7d54c90c937c953 to your computer and use it in GitHub Desktop.
Save the-undefined/fd45a7d54c90c937c953 to your computer and use it in GitHub Desktop.
What to use for the `view_context` in a presenter spec
class Presenter
def user_select_options
view_context.options_from_collection_for_select(
User.all,
:id,
:full_name
)
end
private
attr_reader :view_context
def initialize(view_context: view_context)
@view_context = view_context
end
end
RSpec.describe Presenter do
let(:view_context) { ActionView::Base.new }
describe '#user_select_options' do
it 'should return the users full name' do
presenter = described_class.new(view_context: view_context)
users = [
['Sir Joe James', 1],
['Lord John Doe II', 2],
]
expect(presenter.user_select_options).to match_array(users)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment