GithubHelp home page GithubHelp logo

Comments (7)

kevinrutherford avatar kevinrutherford commented on August 17, 2024

Ash, Thanks for helping me analyse this on Friday! Our conclusion was that there are in fact two problems here:

First, LargeClass goes looking for the class in the object space, and if it finds it then it uses the in-memory class's method count. That shouldn't happen; the test should be based on the supplied chunk of source code. (Could you check that this is indeed occurring in your case? Please run the failing test on its own; if it passes, we know that reek is finding the class in memory from one of your other tests.)

And second, LargeClass should be disabled for in-memory reek parsing. Raised separately as #28.

from reek.

ashmoran avatar ashmoran commented on August 17, 2024

Well I only just got my head round it at the end :)

I will run the spec isolated in just a sec. But I remember we came to the conclusion that in general, the in-memory analysis will differ from the source-based analysis. eg my ugly bit of code:

{ :name => "Name", :identifier => "Identifier" }.each do |property, property_label|
  define_method("dm_validate_#{property}_unique_in_study") do
    property_unique_in_study?(property) || [false, "#{property_label} is already taken"]
  end    
end

MyClass.should_not reek will see two methods here, but a source analysis will see none. Using eval to generate a thousand-line method will be similarly different. And as you say, you may not even have the source that makes these changes. (Maybe this should all go under #28)

So how would you write the documentation to help reek users decide when to do an analysis source-based and when to do it object-based?

from reek.

ashmoran avatar ashmoran commented on August 17, 2024

Behaviour confirmed: in a Merb app, the following line in spec_helper.rb causes the models to load, which causes reek to look in ObjectSpace:

Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')

I have the following line at the top of my reek_spec.rb:

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

I could replace this with:

require 'reek'
require 'reek/spec'

But it will only take effect when that file is run in isolation. I guess I should wait for the bugfix?

from reek.

kevinrutherford avatar kevinrutherford commented on August 17, 2024

I believe this is fixed in e235ca9 (soon to be released as 1.1.3).

from reek.

ashmoran avatar ashmoran commented on August 17, 2024

Nudge me when 1.1.3 is out and I'll switch to the github gems to test it.

from reek.

mrship avatar mrship commented on August 17, 2024

Ashley pointed this release out to me, so I tested it in my environment it is indeed fixed. Many thanks.

from reek.

kevinrutherford avatar kevinrutherford commented on August 17, 2024

Good news -- thanks for the test!

from reek.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.