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

zeus generates empty coverage results with simplecov #131

Closed
xhh opened this Issue Sep 29, 2012 · 22 comments

Comments

Projects
None yet
@xhh

xhh commented Sep 29, 2012

I'm using zeus with rspec and simplecov (for ruby 1.9) in a rails 3 project, and executing

zeus rspec spec

generates empty testing coverage results in coverage/index.html. It is OK when running the tests without zeus.

@marksim

This comment has been minimized.

Show comment
Hide comment
@marksim

marksim Oct 8, 2012

Noticed this as well. Looks like the coverage is run, but somehow a nearly empty coverage report appears.. ideas?

marksim commented Oct 8, 2012

Noticed this as well. Looks like the coverage is run, but somehow a nearly empty coverage report appears.. ideas?

@marksim

This comment has been minimized.

Show comment
Hide comment
@marksim

marksim Oct 16, 2012

What can I provide or look for to help narrow the problem?

marksim commented Oct 16, 2012

What can I provide or look for to help narrow the problem?

@burke

This comment has been minimized.

Show comment
Hide comment
@burke

burke Dec 7, 2012

Owner

I can take a crack at this some point, but I'm not optimistic about the outcome. Code coverage in ruby is super hacky, and so is zeus. Ugly hacks don't often combine well with other ugly hacks.

Owner

burke commented Dec 7, 2012

I can take a crack at this some point, but I'm not optimistic about the outcome. Code coverage in ruby is super hacky, and so is zeus. Ugly hacks don't often combine well with other ugly hacks.

@cousine

This comment has been minimized.

Show comment
Hide comment
@cousine

cousine Jan 30, 2013

Any luck with that? it seems to run fine if using

zeus rake spec

also cucumber generates coverage correctly so I am guessing it has something to do with the RSpec Runner

cousine commented Jan 30, 2013

Any luck with that? it seems to run fine if using

zeus rake spec

also cucumber generates coverage correctly so I am guessing it has something to do with the RSpec Runner

@aokolish

This comment has been minimized.

Show comment
Hide comment
@aokolish

aokolish Feb 18, 2013

This is a bit over my head but I did some debugging and found that simplecov-html is trying to write to the coverage file here: https://github.com/colszowka/simplecov-html/blob/master/lib/simplecov-html.rb#L19

With zeus, it just truncates the file without writing the new content. I set a breakpoint and was only able to file.puts something if I hit the breakpoint without using zeus.

I thought it might be a permissions problem, but it seems not. The output of File#stat seems to be the same with and without zeus.

With zeus rspec spec:

> file.stat
=> #<File::Stat
 dev=0x1000002,
 ino=16607021,
 mode=0100644 (file rw-r--r--),
 nlink=1,
 uid=501 (username),
 gid=20 (staff),
 rdev=0x0 (0, 0),
 size=0,
 blksize=4096,
 blocks=0,
 atime=2013-02-18 01:33:26 -0800 (1361180006),
 mtime=2013-02-18 01:33:24 -0800 (1361180004),
 ctime=2013-02-18 01:33:24 -0800 (1361180004)>

With bundle exec rspec spec:

> file.stat
=> #<File::Stat
 dev=0x1000002,
 ino=16607021,
 mode=0100644 (file rw-r--r--),
 nlink=1,
 uid=501 (username),
 gid=20 (staff),
 rdev=0x0 (0, 0),
 size=0,
 blksize=4096,
 blocks=0,
 atime=2013-02-18 01:34:24 -0800 (1361180064),
 mtime=2013-02-18 01:34:22 -0800 (1361180062),
 ctime=2013-02-18 01:34:22 -0800 (1361180062)>

aokolish commented Feb 18, 2013

This is a bit over my head but I did some debugging and found that simplecov-html is trying to write to the coverage file here: https://github.com/colszowka/simplecov-html/blob/master/lib/simplecov-html.rb#L19

With zeus, it just truncates the file without writing the new content. I set a breakpoint and was only able to file.puts something if I hit the breakpoint without using zeus.

I thought it might be a permissions problem, but it seems not. The output of File#stat seems to be the same with and without zeus.

With zeus rspec spec:

> file.stat
=> #<File::Stat
 dev=0x1000002,
 ino=16607021,
 mode=0100644 (file rw-r--r--),
 nlink=1,
 uid=501 (username),
 gid=20 (staff),
 rdev=0x0 (0, 0),
 size=0,
 blksize=4096,
 blocks=0,
 atime=2013-02-18 01:33:26 -0800 (1361180006),
 mtime=2013-02-18 01:33:24 -0800 (1361180004),
 ctime=2013-02-18 01:33:24 -0800 (1361180004)>

With bundle exec rspec spec:

> file.stat
=> #<File::Stat
 dev=0x1000002,
 ino=16607021,
 mode=0100644 (file rw-r--r--),
 nlink=1,
 uid=501 (username),
 gid=20 (staff),
 rdev=0x0 (0, 0),
 size=0,
 blksize=4096,
 blocks=0,
 atime=2013-02-18 01:34:24 -0800 (1361180064),
 mtime=2013-02-18 01:34:22 -0800 (1361180062),
 ctime=2013-02-18 01:34:22 -0800 (1361180062)>
@aokolish

This comment has been minimized.

Show comment
Hide comment
@aokolish

aokolish Feb 18, 2013

Sorry, I confused myself.

it just truncates the file without writing the new content

That's only true if I set a breakpoint with pry and continue execution.

If I don't set any breakpoints, it writes the file with a coverage % of 0. I'll see if I can come up with something more helpful.

aokolish commented Feb 18, 2013

Sorry, I confused myself.

it just truncates the file without writing the new content

That's only true if I set a breakpoint with pry and continue execution.

If I don't set any breakpoints, it writes the file with a coverage % of 0. I'll see if I can come up with something more helpful.

@aokolish

This comment has been minimized.

Show comment
Hide comment
@aokolish

aokolish Feb 19, 2013

I don't think there is a way for zeus to fix this. I posted a gist of how I got this working: https://gist.github.com/ao140505/4982244

It's not perfect, but it mostly works 😕. Basically, the key is to not SimpleCov.start within your spec helper when running specs with zeus.

I would close this as a non-issue.

aokolish commented Feb 19, 2013

I don't think there is a way for zeus to fix this. I posted a gist of how I got this working: https://gist.github.com/ao140505/4982244

It's not perfect, but it mostly works 😕. Basically, the key is to not SimpleCov.start within your spec helper when running specs with zeus.

I would close this as a non-issue.

@turadg

This comment has been minimized.

Show comment
Hide comment
@turadg

turadg Feb 19, 2013

Collaborator

@ao140505 can you document the work-around on the wiki?

I'd like to leave this open until there's a clear work-around in the docs.

Collaborator

turadg commented Feb 19, 2013

@ao140505 can you document the work-around on the wiki?

I'd like to leave this open until there's a clear work-around in the docs.

@aokolish

This comment has been minimized.

Show comment
Hide comment
@aokolish

aokolish Feb 19, 2013

@turadg sure thing

https://github.com/burke/zeus/wiki/SimpleCov

Feel free to modify that if you think anything is unclear or incorrect. Thanks

aokolish commented Feb 19, 2013

@turadg sure thing

https://github.com/burke/zeus/wiki/SimpleCov

Feel free to modify that if you think anything is unclear or incorrect. Thanks

@turadg

This comment has been minimized.

Show comment
Hide comment
@turadg

turadg Feb 19, 2013

Collaborator

Excellent!

Collaborator

turadg commented Feb 19, 2013

Excellent!

@turadg turadg closed this Feb 19, 2013

@tisba

This comment has been minimized.

Show comment
Hide comment
@tisba

tisba Sep 30, 2013

Thanks for the "fix" :)

The only remaining issue for me is now that I get some "already initialized constant" warnings every time I let zeus run the tests (via guard in my case, but this doesn't matter).

An example constant definition:

class Foo
  # ...
  SOME_CONSTANT = "foo"
  # ...
end

--> "warning: already initialized constant Foo::SOME_CONSTANT"

Any idea how to solve this without suffixing every single constant definition with const_defined?.

/cc @turadg @aokolish

tisba commented Sep 30, 2013

Thanks for the "fix" :)

The only remaining issue for me is now that I get some "already initialized constant" warnings every time I let zeus run the tests (via guard in my case, but this doesn't matter).

An example constant definition:

class Foo
  # ...
  SOME_CONSTANT = "foo"
  # ...
end

--> "warning: already initialized constant Foo::SOME_CONSTANT"

Any idea how to solve this without suffixing every single constant definition with const_defined?.

/cc @turadg @aokolish

@latortuga

This comment has been minimized.

Show comment
Hide comment
@latortuga

latortuga Sep 30, 2013

Collaborator

@tisba can you show the actual code that is generating the warning?

Collaborator

latortuga commented Sep 30, 2013

@tisba can you show the actual code that is generating the warning?

@tisba

This comment has been minimized.

Show comment
Hide comment
@tisba

tisba Oct 1, 2013

@latortuga not sure what you mean. I followed https://github.com/burke/zeus/wiki/SimpleCov and modified my spec_helper.rb and created a custom_plan.rb. When running zeus rspec spec I get the already initialized constant warnings.

tisba commented Oct 1, 2013

@latortuga not sure what you mean. I followed https://github.com/burke/zeus/wiki/SimpleCov and modified my spec_helper.rb and created a custom_plan.rb. When running zeus rspec spec I get the already initialized constant warnings.

@latortuga

This comment has been minimized.

Show comment
Hide comment
@latortuga

latortuga Oct 1, 2013

Collaborator

not sure what you mean

I mean: what is the actual warning, what is the actual line of code that is generating the warning, what is the actual code context around the line generating the warning?

Note: I did not ask "what is an example of the warning". From lots of time spent on IRC, I have found that people post bad examples of their code and the issue often is very obvious when the actual code that is causing an issue is shown.

Collaborator

latortuga commented Oct 1, 2013

not sure what you mean

I mean: what is the actual warning, what is the actual line of code that is generating the warning, what is the actual code context around the line generating the warning?

Note: I did not ask "what is an example of the warning". From lots of time spent on IRC, I have found that people post bad examples of their code and the issue often is very obvious when the actual code that is causing an issue is shown.

@tisba

This comment has been minimized.

Show comment
Hide comment
@tisba

tisba Oct 1, 2013

@latortuga https://gist.github.com/tisba/b0023262f65b7b088b83 is one of the sources throwing the following warnings (there are a couple of more, but this is one example I can show without modification):

/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:2: warning: already initialized constant FileSizeValidator::MESSAGES
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:2: warning: previous definition of MESSAGES was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:3: warning: already initialized constant FileSizeValidator::CHECKS
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:3: warning: previous definition of CHECKS was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:5: warning: already initialized constant FileSizeValidator::DEFAULT_TOKENIZER
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:5: warning: previous definition of DEFAULT_TOKENIZER was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:6: warning: already initialized constant FileSizeValidator::RESERVED_OPTIONS
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:6: warning: previous definition of RESERVED_OPTIONS was here

tisba commented Oct 1, 2013

@latortuga https://gist.github.com/tisba/b0023262f65b7b088b83 is one of the sources throwing the following warnings (there are a couple of more, but this is one example I can show without modification):

/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:2: warning: already initialized constant FileSizeValidator::MESSAGES
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:2: warning: previous definition of MESSAGES was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:3: warning: already initialized constant FileSizeValidator::CHECKS
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:3: warning: previous definition of CHECKS was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:5: warning: already initialized constant FileSizeValidator::DEFAULT_TOKENIZER
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:5: warning: previous definition of DEFAULT_TOKENIZER was here
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:6: warning: already initialized constant FileSizeValidator::RESERVED_OPTIONS
/Users/basti/Documents/work/freelancing/project/webapp/app/validators/file_size_validator.rb:6: warning: previous definition of RESERVED_OPTIONS was here
@robwil

This comment has been minimized.

Show comment
Hide comment
@robwil

robwil Dec 17, 2013

@tisba @aokolish Following the exact instructions at the https://github.com/burke/zeus/wiki/SimpleCov wiki page, I am seeing the Constant redefinition warnings as well. I'm happy to ignore those.

However, I think what's actually happening is that my models are being loaded twice. This is showing up because some of my tests in the format of expect(post).to have(1).errors_on(:contents) are failing because they have 2 errors. Debugging shows that my validation error messages contain duplicate errors, e.g. ["can't be blank", "can't be blank"].

robwil commented Dec 17, 2013

@tisba @aokolish Following the exact instructions at the https://github.com/burke/zeus/wiki/SimpleCov wiki page, I am seeing the Constant redefinition warnings as well. I'm happy to ignore those.

However, I think what's actually happening is that my models are being loaded twice. This is showing up because some of my tests in the format of expect(post).to have(1).errors_on(:contents) are failing because they have 2 errors. Debugging shows that my validation error messages contain duplicate errors, e.g. ["can't be blank", "can't be blank"].

@johaned

This comment has been minimized.

Show comment
Hide comment
@johaned

johaned Nov 23, 2014

Hi, sorry my english is not the best around, i'm working on Rails 4 and i have some "concerns" associated with my controllers, the proposed solution about simplecov-zeus does not work for me, the problem is about ActiveSupport::Concern::MultipleIncludedBlocks there is a duplication process in the loading process, A solution to this problem was found with the skipping of "concern" directories, because it seems like the modules are being loaded twice (due to the loading sequence), I don't know if this solution is well

Dir["#{Rails.root}/app/**/*.rb"].reject{ |f| f[%r{/app/controllers/concerns/}] || f[%r{/app/models/concerns/}]  }.each { |f| load f }

johaned commented Nov 23, 2014

Hi, sorry my english is not the best around, i'm working on Rails 4 and i have some "concerns" associated with my controllers, the proposed solution about simplecov-zeus does not work for me, the problem is about ActiveSupport::Concern::MultipleIncludedBlocks there is a duplication process in the loading process, A solution to this problem was found with the skipping of "concern" directories, because it seems like the modules are being loaded twice (due to the loading sequence), I don't know if this solution is well

Dir["#{Rails.root}/app/**/*.rb"].reject{ |f| f[%r{/app/controllers/concerns/}] || f[%r{/app/models/concerns/}]  }.each { |f| load f }
@guapolo

This comment has been minimized.

Show comment
Hide comment
@guapolo

guapolo Mar 31, 2015

@johaned suggestion worked form me using Rails 4, Zeus 0.15.4, ruby 2.2.

Is it ok if I edit the Wiki page to reflect this solution when using Rails >= 4?

guapolo commented Mar 31, 2015

@johaned suggestion worked form me using Rails 4, Zeus 0.15.4, ruby 2.2.

Is it ok if I edit the Wiki page to reflect this solution when using Rails >= 4?

@johaned

This comment has been minimized.

Show comment
Hide comment
@johaned

johaned Mar 31, 2015

hey @guapolo
sure, no problem 👍

johaned commented Mar 31, 2015

hey @guapolo
sure, no problem 👍

@xero88

This comment has been minimized.

Show comment
Hide comment
@xero88

xero88 Nov 22, 2017

This is not working for me.

I get :

You tried to define an enum named "available_roles" on the model "User", but this will generate a instance method "admin?", which is already defined by another enum. (ArgumentError)

xero88 commented Nov 22, 2017

This is not working for me.

I get :

You tried to define an enum named "available_roles" on the model "User", but this will generate a instance method "admin?", which is already defined by another enum. (ArgumentError)

@guapolo

This comment has been minimized.

Show comment
Hide comment
@guapolo

guapolo Nov 28, 2017

@xero88 that's a Rails enum thing. You defined two enums on your model with an element named :admin. You can't repeat enum element names on the same model.

guapolo commented Nov 28, 2017

@xero88 that's a Rails enum thing. You defined two enums on your model with an element named :admin. You can't repeat enum element names on the same model.

@xero88

This comment has been minimized.

Show comment
Hide comment
@xero88

xero88 Feb 13, 2018

@guapolo no I have not. When I change the element, I get :

You tried to define an enum named "available_roles" on the model "User", but this will generate a instance method "adminaa?", which is already defined by another enum. (ArgumentError)

xero88 commented Feb 13, 2018

@guapolo no I have not. When I change the element, I get :

You tried to define an enum named "available_roles" on the model "User", but this will generate a instance method "adminaa?", which is already defined by another enum. (ArgumentError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment