rubyatscale / singed

Get a flamegraph anywhere in your code base. Powered by stackprof, rbspy, and speedscope
MIT License
408 stars 9 forks source link

Running in project with rspec #3

Closed kivanio closed 1 year ago

kivanio commented 1 year ago

It needs to clarify at README that in projects with rspec, the gem 'singed' needs to be at same group as rspecgem in your Gemfile.

Otherwise you get this:

bundle exec singed -- bin/rails runner 'User.all.to_a'
You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
bundler: failed to load command: singed (/Users/kivanio/.rbenv/versions/3.2.1/bin/singed)
/Users/kivanio/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/singed-0.1.1/lib/singed/rspec.rb:3:in `<main>': undefined method `configure' for RSpec:Module (NoMethodError)

RSpec.configure do |config|
     ^^^^^^^^^^
Overload119 commented 1 year ago

It'd be nice to remove the dependency on rspec completely.

technicalpickles commented 1 year ago

How are you including singed in your project? I'm confused how singed/rspec is loaded because singed only requires it if RSpec is defined:

https://github.com/rubyatscale/singed/blob/ee1c84d7a76eee595ac58c5e5f5b04785d8c2458/lib/singed.rb#L56

We could remove that line, and add an explicit configuration step to rspec, ie require 'singed/rspec'.

Overload119 commented 1 year ago

Ah, I think this is because I have rspec-rails required but not rspec

[3] pry(main)> defined?(RSpec)
=> "constant"
[4] pry(main)> RSpec.configure
NoMethodError: undefined method `configure' for RSpec:Module
from (pry):3:in `__pry__'
[5] pry(main)> Object.const_source_location('RSpec')
=> ["/Users/amirsharif/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rspec-rails-6.0.1/lib/rspec/rails/feature_check.rb",
 1]
[6] pry(main)>

I removed this from my Gemfile and it works. Perhaps we check for the configure via respond_to or just do nothing.

kivanio commented 1 year ago

Same here I only require rspec-rails at my Rails app