简体   繁体   中英

Why does the Cucumber test app fail to access Sinatra's settings in 1.4.x but not 1.3.x?

I was trying to upgrade from Sinatra 1.3.x to 1.4.2. The specs run fine, but Cucumber fails with:

undefined local variable or method `settings' for #<RechargeWorld:0x007ffbd606ba60> (NameError)

The relevant portion of the env.rb looks like this:

  class RechargeWorld
    include Capybara::DSL
    include RSpec::Expectations
    include RSpec::Matchers

    def db
      @db ||= CouchRest.database(settings.db)
    end
  end

Some of this code (note: I added the db method) was generated by cucumber-sintra , and it worked fine with 1.3.x but fails with any version 1.4.x. The latest version of cucumber-sinatra generates basically an identical env.rb .

The app is available on Github .

Was anything changed with the settings hash between 1.3.x and 1.4 that could be causing this? Am I doing it wrong?

I looked into the official Cucumber+Sinatra guide and noticed the app method returning Sinatra::Application .

So I changed the env.rb portion to this:

class RechargeWorld
  include Capybara::DSL
  include RSpec::Expectations
  include RSpec::Matchers

  def db
    @db ||= CouchRest.database(Sinatra::Application.settings.db)
  end
end

and it works like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM