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

infer_spec_type_from_file_location! wrongly set in project not using rspec-rails #88

Closed
myronmarston opened this issue Aug 27, 2014 · 2 comments

Comments

@myronmarston
Copy link

I used the latest transpec against rspec-mocks as a way to convert to the RSpec.describe form (see rspec/rspec-mocks#768), and I found that transpec wrongly generated config.infer_spec_type_from_file_location! even though rspec-rails isn't loaded and therefore that method isn't available.

➜  rspec-mocks git:(master) ruby --version
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]
➜  rspec-mocks git:(master) transpec --version
2.3.6
➜  rspec-mocks git:(master) git show | grep commit
commit fd9cd38fa01aed46c43c1072448aeb5de24abd50
➜  rspec-mocks git:(master) transpec -s -a -t -p --keep should,oneliner,should_receive,stub,have_items,its,pending,deprecated --convert example_group
Gathering the spec suite data...

Converting spec/rspec/mocks/and_call_original_spec.rb
Converting spec/rspec/mocks/and_return_spec.rb
Converting spec/rspec/mocks/and_wrap_original_spec.rb
Converting spec/rspec/mocks/and_yield_spec.rb
Converting spec/rspec/mocks/any_instance/message_chains_spec.rb
Converting spec/rspec/mocks/any_instance_spec.rb
Converting spec/rspec/mocks/argument_matchers_spec.rb
Converting spec/rspec/mocks/array_including_matcher_spec.rb
Converting spec/rspec/mocks/at_least_spec.rb
Converting spec/rspec/mocks/at_most_spec.rb
Converting spec/rspec/mocks/before_all_spec.rb
Converting spec/rspec/mocks/block_return_value_spec.rb
Converting spec/rspec/mocks/combining_implementation_instructions_spec.rb
Converting spec/rspec/mocks/configuration_spec.rb
Converting spec/rspec/mocks/double_spec.rb
Converting spec/rspec/mocks/example_methods_spec.rb
Converting spec/rspec/mocks/expiration_spec.rb
Converting spec/rspec/mocks/hash_excluding_matcher_spec.rb
Converting spec/rspec/mocks/hash_including_matcher_spec.rb
Converting spec/rspec/mocks/instance_method_stasher_spec.rb
Converting spec/rspec/mocks/marshal_extension_spec.rb
Converting spec/rspec/mocks/matchers/have_received_spec.rb
Converting spec/rspec/mocks/matchers/receive_message_chain_spec.rb
Converting spec/rspec/mocks/matchers/receive_messages_spec.rb
Converting spec/rspec/mocks/matchers/receive_spec.rb
Converting spec/rspec/mocks/methods_spec.rb
Converting spec/rspec/mocks/mock_expectation_error_spec.rb
Converting spec/rspec/mocks/mock_ordering_spec.rb
Converting spec/rspec/mocks/multiple_return_value_spec.rb
Converting spec/rspec/mocks/mutate_const_spec.rb
Converting spec/rspec/mocks/nil_expectation_warning_spec.rb
Converting spec/rspec/mocks/null_object_double_spec.rb
Converting spec/rspec/mocks/once_counts_spec.rb
Converting spec/rspec/mocks/order_group_spec.rb
Converting spec/rspec/mocks/partial_double_spec.rb
Converting spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb
Converting spec/rspec/mocks/precise_counts_spec.rb
Converting spec/rspec/mocks/serialization_spec.rb
Converting spec/rspec/mocks/should_syntax_spec.rb
Converting spec/rspec/mocks/space_spec.rb
Converting spec/rspec/mocks/spy_spec.rb
Converting spec/rspec/mocks/stash_spec.rb
Converting spec/rspec/mocks/stub_chain_spec.rb
Converting spec/rspec/mocks/stub_implementation_spec.rb
Converting spec/rspec/mocks/stub_spec.rb
Converting spec/rspec/mocks/stubbed_message_expectations_spec.rb
Converting spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb
Converting spec/rspec/mocks/syntax_spec.rb
Converting spec/rspec/mocks/test_double_spec.rb
Converting spec/rspec/mocks/thrice_counts_spec.rb
Converting spec/rspec/mocks/to_ary_spec.rb
Converting spec/rspec/mocks/twice_counts_spec.rb
Converting spec/rspec/mocks/verifying_double_spec.rb
Converting spec/rspec/mocks/verifying_message_expecation_spec.rb
Converting spec/rspec/mocks_spec.rb
Converting spec/spec_helper.rb
Converting spec/support/before_all_shared_example_group.rb
Converting spec/support/matchers.rb

Summary:

82 conversions
  from: describe 'something' { }
    to: RSpec.describe 'something' { }
4 conversions
  from: context 'something' { }
    to: RSpec.context 'something' { }
4 conversions
  from: shared_context 'something' { }
    to: RSpec.shared_context 'something' { }
4 additions
    of: RSpec.configure { |c| c.expose_dsl_globally = false }
4 additions
    of: RSpec.configure { |c| c.infer_spec_type_from_file_location! }
3 conversions
  from: shared_examples 'something' { }
    to: RSpec.shared_examples 'something' { }
1 conversion
  from: shared_examples_for 'something' { }
    to: RSpec.shared_examples_for 'something' { }

102 conversions, 0 incompletes, 0 warnings, 0 errors

A commit message that describes the conversion summary was generated to
.git/COMMIT_EDITMSG. To use the message, type the following command for
the next commit:
    git commit -aeF .git/COMMIT_EDITMSG

Done! Now run rspec and check if everything is green.
@yujinakayama
Copy link
Owner

It's because you passed both -s/--skip-dynamic-analysis and -t/--no-explicit-spec-type.

Transpec checks if rspec-rails is loaded in your specs with dynamic analysis, so if dynamic analysis is skipped, it aggressively considers that the project is using rspec-rails. However in most cases this behavior won't be problematic since Transpec adds explicit spec type metadata only to spec files in the typical rspec-rails directory structure (e.g. spec/controllers) and does not add the infer_spec_type_from_file_location! unless you pass -t/--no-explicit-spec-type.

Note that some conversion options other than -k/--keep (e.g. -t/--no-explicit-spec-type and -a/--no-yield-any-instance) are not switches for enabling/disabling conversions, they are switches for changing the conversion behavior. So you don't need to pass -t/--no-explicit-spec-type in non-rails projects.

That said, I'm thinking about adding Gemfile analysis for cases like this.

By the way, basically the use of -s/--skip-dynamic-analysis is discouraged. It would be useful only if your spec suite takes really long (like an hour) to run so you prefer a combination of rough but fast conversion by Transpec and manual fixes after that.

@myronmarston
Copy link
Author

By the way, basically the use of -s/--skip-dynamic-analysis is discouraged. It would be useful only if your spec suite takes really long (like an hour) to run so you prefer a combination of rough but fast conversion by Transpec and manual fixes after that.

Makes sense. I (wrongly) thought that the dynamic analysis wasn't going to be involved in the updates I wanted transpec to apply. It might be worth emphasing how important the dynamic analysis bit is in the README. (Or maybe it already is emphasized but I haven't read your README recently...)

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

No branches or pull requests

2 participants