lookbook-hq / lookbook

A UI development environment for Ruby on Rails apps ✨
https://lookbook.build
MIT License
881 stars 91 forks source link

NameError: uninitialized constant ComponentPreview::RSpec #65

Closed jankeesvw closed 2 years ago

jankeesvw commented 2 years ago

We just bumped lookbook from 0.6.1 to 0.7.1, and we are now seeing this while deploying.

Is anyone else seeing this issue?


NameError: uninitialized constant MeterReadingGraphComponentPreview::RSpec
spec/components/previews/meter_reading_graph_component_preview.rb:2:in `<class:MeterReadingGraphComponentPreview>'
spec/components/previews/meter_reading_graph_component_preview.rb:1:in `<main>'
config/environment.rb:5:in `<main>'
/home/deploy/.rbenv/versions/3.0.2/bin/bundle:23:in `load'
/home/deploy/.rbenv/versions/3.0.2/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
allmarkedup commented 2 years ago

Hey @jankeesvw - thanks for the bug report. That is an odd one - is it possible to post the contents of the spec/components/previews/meter_reading_graph_component_preview.rb so I can take a look and see if I can spot anything that might be causing the issue?

jankeesvw commented 2 years ago

Hey @allmarkedup,

Of course:

class MeterReadingGraphComponentPreview < ViewComponent::Preview
  include RSpec::Mocks::ExampleMethods

  def default
    readings = [{ reading_kwh: "0.56", mid_certified: false, timestamp: "2022-02-01T16:20:03.000Z" }]
    session = Session.new

    session.meter_readings = readings.map { |data|
      MeterReading.new(data)
    }
    session.start_at = Time.parse("2022-02-01 16:20:01 UTC")
    session.end_at = Time.parse("2022-02-01 21:49:13 UTC")

    meter_reading_graph_component_new = MeterReadingGraphComponent.new(session: session)
    allow(meter_reading_graph_component_new).to receive(:market_prices).and_return([].to_json)
    render(meter_reading_graph_component_new)
  end

  def bigger_graph
    readings = [{ timestamp: "2022-02-12T08:59:30.000Z", mid_certified: false, reading_kwh: 0.0 }]

    meter_readings = readings.map { |data|
      MeterReading.new(data)
    }

    price_profile = double(TimeProfile, time_profile: { "2022-02-12T08:59:30.000Z": 90, "2022-02-12T10:59:30.000Z": 100, "2022-02-12T11:59:30.000Z": 60, "2022-02-13T12:38:52.000Z": 10 })

    session = double(Session,
                     meter_readings: meter_readings,
                     start_at: Time.parse("2022-02-12T08:59:30.000Z"),
                     end_at: Time.parse("2022-02-13T12:38:52.000Z"),
                     site: double(Site, epex?: true, solar?: false, price_profile: price_profile))

    render(MeterReadingGraphComponent.new(session: session))
  end
end
allmarkedup commented 2 years ago

Thanks @jankeesvw that is great - I'm digging into it a bit now.

I'm not sure why the recent update should affect this, but out of interest are you explicitly requiring the rspec mocks somewhere in your config/application.rb (or in an environment-specific config file somewhere)? I've just found this issue which suggests that you might need to explcitly have a require "rspec/mocks" statement somewhere.

Either way, if it was working before it should really still be working so I'll try and figure out what might be different at the Lookbook end of things and update here if I find anything.

allmarkedup commented 2 years ago

Hey again @jankeesvw,

I've just pushed up a beta release with some improvements to the way preview files are loaded (amongst other things). If you have a chance at some point could you see if it fixes the problem you are seeing with the 0.7.1 release?

The beta release is v0.7.2-beta.0 and is installable from Rubygems as normal.

Thanks!

jankeesvw commented 2 years ago

Hi @allmarkedup, we've just successfully deployed 0.7.2.beta.2, this works without any issues.

Thanks for helping on such short notice. ✨

allmarkedup commented 2 years ago

@jankeesvw ah great, my pleasure, and glad to know it fixed your issue :-)