Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use :format as default exposure for view unit tests. #860

Merged
merged 1 commit into from
Nov 20, 2017

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Nov 7, 2017

This is a proposal for both a fix and a small enhancement for view unit tests.

The Fix

If you're running unit tests of a view that renders a template, without format: :html in the exposures, it raises an error. See hanami/view#137

So instead of generating unit tests with bogus exposures (foo: "bar"), we can generate with useful exposures (format: :html).

The enhancement

Given we were setting bogus exposures, we took the decision of marking that unit tests as pending. Now that we have real exposures, it's worth to test for real that the view is using :html as a format.

So the proposal is to generate unit tests that are no longer pending.


This is related to the proposals that @cllns made with #831


Fixes hanami/view#137
Closes #831
Ref #664

@jodosha jodosha self-assigned this Nov 7, 2017
@jodosha jodosha requested review from cllns, AlfonsoUceda and a team November 7, 2017 14:27
@jodosha jodosha added this to the v1.1.1 milestone Nov 7, 2017
Copy link
Contributor

@AlfonsoUceda AlfonsoUceda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@mereghost mereghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@davydovanton davydovanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@jodosha jodosha merged commit 8ba872b into master Nov 20, 2017
@jodosha jodosha deleted the enhancement/format-local-for-view-unit-tests branch November 20, 2017 13:38
@jdickey
Copy link

jdickey commented May 23, 2018

Note that this workaround is still necessary to get specs for views with partials to not crash as of Hanami 1.2.0.

@calexandrepcjr
Copy link

@jdickey Yeah, I'm receiving an error when my application.html.erb has partials:

bundle exec rake
Run options: --seed 19802

# Running:

......E.....

Finished in 0.494269s, 24.2783 runs/s, 42.4869 assertions/s.

  1) Error:
Web::Views::ApplicationLayout#test_0001_contains application name:
NoMethodError: undefined method `view' for #<Hanami::View::Template:0x000055bc3a6ae838>
    /usr/local/bundle/gems/hanami-view-1.2.0/lib/hanami/view/rendering/layout_scope.rb:120:in `view'
    /usr/local/bundle/gems/hanami-view-1.2.0/lib/hanami/view/rendering/layout_scope.rb:252:in `renderer'
    /usr/local/bundle/gems/hanami-view-1.2.0/lib/hanami/view/rendering/layout_scope.rb:102:in `render'
    /opt/telzir/apps/web/templates/application.html.erb:8:in `block in singleton class'
    /opt/telzir/apps/web/templates/application.html.erb:-2:in `instance_eval'
    /opt/telzir/apps/web/templates/application.html.erb:-2:in `singleton class'
    /opt/telzir/apps/web/templates/application.html.erb:-5:in `__tilt_47133452600820'
    /usr/local/bundle/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `call'
    /usr/local/bundle/gems/tilt-2.0.8/lib/tilt/template.rb:170:in `evaluate'
    /usr/local/bundle/gems/tilt-2.0.8/lib/tilt/template.rb:109:in `render'
    /usr/local/bundle/gems/hanami-view-1.2.0/lib/hanami/view/template.rb:41:in `render'
    /usr/local/bundle/gems/hanami-view-1.2.0/lib/hanami/layout.rb:139:in `render'
    /opt/telzir/spec/web/views/application_layout_spec.rb:6:in `block (2 levels) in <top (required)>'

12 runs, 21 assertions, 0 failures, 1 errors, 0 skips
rake aborted!

cllns added a commit to hanami/bookshelf that referenced this pull request Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View specs fail when view renders partial Generating View Spec?
6 participants