RSpec.describe 'dry-view' do let(:view_class) do klass = Class.new(Dry::View::Layout) klass.configure do |config| config.root = SPEC_ROOT.join('fixtures/templates') config.name = 'app' config.template = 'users' config.formats = {html: :slim, txt: :erb} end klass end let(:scope) do Struct.new(:title).new('dry-view rocks!') end it 'renders within a layout using provided scope' do view = view_class.new users = [ { name: 'Jane', email: 'jane@doe.org' }, { name: 'Joe', email: 'joe@doe.org' } ] expect(view.(scope: scope, locals: { subtitle: "Users List", users: users })).to eql( 'dry-view rocks!

Users List

Janejane@doe.org
Joejoe@doe.org
' ) end it 'renders a view with an alternative format and engine' do view = view_class.new users = [ { name: 'Jane', email: 'jane@doe.org' }, { name: 'Joe', email: 'joe@doe.org' } ] expect(view.(scope: scope, locals: { subtitle: 'Users List', users: users }, format: 'txt').strip).to eql( "# dry-view rocks!\n\n## Users List\n\n* Jane (jane@doe.org)\n* Joe (joe@doe.org)" ) end describe 'inheritance' do let(:parent_view) do klass = Class.new(Dry::View::Layout) klass.setting :root, SPEC_ROOT.join('fixtures/templates') klass.setting :name, 'app' klass.setting :formats, {html: :slim} klass end let(:child_view) do Class.new(parent_view) do configure do |config| config.template = 'tasks' end end end it 'renders within a parent class layout using provided scope' do view = child_view.new expect(view.(scope: scope, locals: { tasks: [{ title: 'one' }, { title: 'two' }] })).to eql( 'dry-view rocks!
  1. one
  2. two
' ) end end end