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

webrat's have_selector does not give deprecation warning in rspec 2.99 but fails in rspec 3 #2085

Closed
richardwan opened this issue Oct 10, 2015 · 4 comments
Labels

Comments

@richardwan
Copy link

if i understand the info in http://rspec.info/upgrading-from-rspec-2/ correctly, an rspec 3 failure with no corresponding 2.99 deprecation warning is considered a bug.

details:

  • using webrat 0.7.3 with expect(some_string).to have_selector 'blahblah', ran fine with no deprecation warning in 2.99

  • upgraded to rspec 3 and it started trying to call has_selector? on the string and gave an error

  • worked around the issue by putting a declaration in spec_helper

    def have_selector(name, attributes = {}, &block)
    Webrat::Matchers::HaveSelector.new(name, attributes, &block)
    end

@myronmarston
Copy link
Member

Thanks for reporting this. It looks like we just forgot to add a deprecation to 2.99 for this :(. Specifically, this is what happened from what I can tell:

  • In rspec-rails 2.99, it included the webrat matchers via a bunch of config.include statements in rspec/rails/vendor/webrat, which was always loaded from rspec/rails.
  • In Removes --webrat rspec-rails#850 the --webrat flag was removed from the generator (which did not need a deprecation in 2.99 since it didn't affect existing code) but we also removed the line from rspec/rails that loaded rspec/rails/vendor/webrat. No deprecation was added for the changes in this PR since we (wrongly) thought it was just affecting the generator.
  • @cupakromer removed the rspec/rails/vendor/webrat file in Remove remaining vendored webrat. rspec-rails#1011 but thought it was a no-op since there were no references to the file (since the prior PR had already removed the require but we didn't notice that...) so we didn't add a deprecation then, either.

So we just flat-out missed the deprecation on this one. Sorry about that!

@cupakromer, do you want to work up a PR for 2.99 that adds a deprecation for this?

To fix it, you can essentially bring back what the deleted file was doing in 2.x:

begin
  require 'webrat'
rescue LoadError
end

RSpec.configure do |c|
  if defined?(Webrat)
    c.include Webrat::Matchers, :type => :request
    c.include Webrat::Matchers, :type => :controller
    c.include Webrat::Matchers, :type => :view
    c.include Webrat::Matchers, :type => :helper
    c.include Webrat::Matchers, :type => :mailer

    c.include Webrat::Methods,  :type => :request
    c.include Webrat::Methods,  :type => :controller

    module RequestInstanceMethods
      def last_response
        @response
      end
    end

    c.include RequestInstanceMethods, :type => :request

    c.before :type => :controller do
      Webrat.configure {|w| w.mode = :rails}
    end

    c.before :type => :request do
      Webrat.configure {|w| w.mode = :rack}
    end
  end
end

You may not need all of that but for full backwards compatility with what was happening in 2.x it's all needed.

@richardwan
Copy link
Author

thanks. by the way awesome job with the whole 2.99, transpec, 3.x upgrade path. it handles so many cases.

@xaviershay xaviershay added the Bug label Jan 15, 2017
@mikegee
Copy link

mikegee commented Aug 29, 2018

As time passes, the value of fixing this becomes lower than the effort required. Perhaps we've already crossed the threshold were this should be closed unfixed?

@myronmarston
Copy link
Member

Agree. Closing.

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

4 participants