lucky icon indicating copy to clipboard operation
lucky copied to clipboard

using visit with class name reports "Error: undefined constant User"

Open jeremyjung opened this issue 4 years ago • 9 comments

OS: Ubuntu 20.04 LTS (Running in VMware Workstation), 2 processors, 4gb RAM

Setup:

  1. lucky init
  2. Full support
  3. No authentication

Created spec/flows/visit_home_spec.cr with following contents:

require "../spec_helper"

describe "home" do
  it "should visit index" do
    HomePageFlow.new.visit_index
  end
end

class HomePageFlow < BaseFlow
  def visit_index
    visit Home::Index
    el("h1.headline", text: "Not sure where to start? Here are some ideas:").should be_on_page
  end
end

Expected: Success Result:

crystal spec
Showing last frame. Use --error-trace for full trace.

In lib/lucky_flow/src/lucky_flow.cr:26:53

 26 | def visit(action : Lucky::Action.class, as user : User? = nil)
                                                        ^---
Error: undefined constant User

Replacing visit Home::Index with visit "/" results in the following successful result:

crystal spec
[1588919861.480][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919861.581][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919861.683][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919861.785][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919861.887][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919861.992][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.093][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.194][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.296][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.398][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.499][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.601][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.702][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.804][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919862.906][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.008][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.109][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.211][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.312][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.413][SEVERE]: Timed out receiving message from renderer: 0.100
[1588919863.514][SEVERE]: Timed out receiving message from renderer: 0.100
.

Finished in 2.65 seconds
1 examples, 0 failures, 0 errors, 0 pending

jeremyjung avatar May 08 '20 06:05 jeremyjung

Related: https://github.com/luckyframework/lucky_flow/issues/65

jwoertink avatar May 08 '20 15:05 jwoertink

Ah, I should have checked the lucky_flow repo. That workaround looks good for now.

jeremyjung avatar May 08 '20 15:05 jeremyjung

Glad you have a workaround. We'll definitely fix this though so won't be necessary in the future :D

paulcsmith avatar May 11 '20 14:05 paulcsmith

Does it make sense that since Authentic is built on top of lucky that it could also include some test helpers for LuckyFlow? That way the helper can take in an Authentic::PasswordAuthenticatable instead of a User

matthewmcgarvey avatar May 15 '20 03:05 matthewmcgarvey

I haven't looked in to it much, but that sounds good.

jwoertink avatar May 15 '20 14:05 jwoertink

@matthewmcgarvey Oh I love that idea!

I think we'll still want to extract the visit method that accepts an as to a module that is not included by default. We would include it only when generating Lucky with auth enabled.

Does that make sense?

paulcsmith avatar May 15 '20 14:05 paulcsmith

My thoughts were that there would be an Authentic::Spec module and generated apps would have a require "authentic/spec" put in the spec_helper file which would include anything that would help with tests, and specifically these visit methods.

@paulcsmith Is that what you're getting at?

matthewmcgarvey avatar May 15 '20 17:05 matthewmcgarvey

Yes I think that or something similar would be awesome 👍

paulcsmith avatar May 15 '20 19:05 paulcsmith

Finally getting around to fixing this :joy:

Ref: https://github.com/luckyframework/lucky_flow/pull/152

jwoertink avatar Aug 29 '22 00:08 jwoertink