Skip to content
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

rspec command without explicit paths runs each test twice #27

Open
EmersonPrado opened this issue Sep 11, 2022 · 1 comment
Open

rspec command without explicit paths runs each test twice #27

EmersonPrado opened this issue Sep 11, 2022 · 1 comment
Labels

Comments

@EmersonPrado
Copy link

Describe the Bug

I set up a rspec-puppet Vagrant playground to learn and train, with very basic settings, artifacts and tests. Command rspec runs perfectly if I give it each directory with test specs. But, If I give it a general path like spec/, or don't specify the path, it runs each test twice.

# I have 4 tests total in classes and defines, plus the coverage test

rspec spec/{classes,defines}
...
5 examples, 0 failures

rspec spec/
...
9 examples, 0 failures

Expected Behavior

The "examples" count at the end should match the exact count of test definitions

Steps to Reproduce

spec/spec_helper.rb

require 'rspec-puppet'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

RSpec.configure do |c|
  c.module_path = File.join(fixture_path, 'modules')
  c.manifest_dir = File.join(fixture_path, 'manifests')
  c.parser = 'future'
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!
  end
end

spec/classes/init_spec.rb

require 'spec_helper'

describe 'rspec_test' do

  it { is_expected.to compile }
  it { is_expected.to create_class('rspec_test')}

end

spec/defines/rspec_test__type_spec.rb

require 'spec_helper'

describe 'rspec_test::type' do

  let(:title) { 'title' }

  it { is_expected.to compile }
  it { is_expected.to create_rspec_test__type('title') }

end

Directory structure

rspec_test $ ls -lAR
.:
total 12
-rw-r--r-- 1 grilo grilo   72 set 10 18:12 Gemfile
drwxr-sr-x 2 grilo grilo 4096 set 10 18:35 manifests
drwxr-sr-x 5 grilo grilo 4096 set 10 18:35 spec

./manifests:
total 8
-rw-r--r-- 1 grilo grilo 69 set 10 18:35 init.pp
-rw-r--r-- 1 grilo grilo 83 set 10 18:35 type.pp

./spec:
total 16
drwxr-sr-x 2 grilo grilo 4096 set 10 18:35 classes
drwxr-sr-x 2 grilo grilo 4096 set 10 18:35 defines
drwxr-sr-x 4 grilo grilo 4096 set 10 18:35 fixtures
-rw-r--r-- 1 grilo grilo  317 set 11 15:10 spec_helper.rb

./spec/classes:
total 4
-rw-r--r-- 1 grilo grilo 136 set 11 14:19 init_spec.rb

./spec/defines:
total 4
-rw-r--r-- 1 grilo grilo 176 set 11 14:19 rspec_test__type_spec.rb

./spec/fixtures:
total 8
drwxr-sr-x 2 grilo grilo 4096 set 10 18:35 manifests
drwxr-sr-x 2 grilo grilo 4096 set 11 15:09 modules

./spec/fixtures/manifests:
total 0
-rw-r--r-- 1 grilo grilo 0 set 10 18:35 site.pp

./spec/fixtures/modules:
total 0
lrwxrwxrwx 1 grilo grilo 9 set 11 15:09 rspec_test -> ../../../

Environment

  • Rspec-related gems
    • rspec (3.11.0)
    • rspec-core (3.11.0)
    • rspec-expectations (3.11.0)
    • rspec-mocks (3.11.1)
    • rspec-puppet (2.12.0)
    • rspec-support (3.11.0)
  • OS stuff
    • Kernel: 4.19.0-21-amd64
    • Distro: Linux Mint Debian Edition 4 (Debbie)
      • Base: Debian 10.2
    • Ruby: 2.5.5p157
    • Puppet: 7.18.0

Additional Context

I kinda suspect the module symlink has something to do with it, because it makes spec_helper.rb appear recursively. But this would be strange, because:

  1. It would trigger tests indefinitely, not just twice.
  2. The symlink, if I got it right, is a requirement (at least, I couldn't make it work without it).

I didn't set up Rake because I want to understand bare Rspec-Puppet first.

Thanks,
Emerson

@EmersonPrado
Copy link
Author

It seems the symlink does affect the issue. I replaced the symlink with a copy of the module, without rspec files, and the test count matched:

rspec_test $ rm spec/fixtures/modules/rspec_test
rspec_test $ mkdir spec/fixtures/modules/rspec_test
rspec_test $ cp -r manifests spec/fixtures/modules/rspec_test/
rspec_test $ ls -lR spec/fixtures/modules/rspec_test/
spec/fixtures/modules/rspec_test/:
total 4
drwxr-sr-x 2 grilo grilo 4096 set 11 16:24 manifests

spec/fixtures/modules/rspec_test/manifests:
total 8
-rw-r--r-- 1 grilo grilo 69 set 11 16:24 init.pp
-rw-r--r-- 1 grilo grilo 83 set 11 16:24 type.pp

rspec_test $ rspec
...
5 examples, 0 failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant