简体   繁体   中英

`<module:Types>': undefined method `/' for #<String:0x007fd44c8f5318> (NoMethodError) Datamapper

I am receiving this error when attempting to run RSpec. I just was setting DataMapper up on my app and I have received this error. I have been trying to debug it myself but I don't understand the stacktrace and where it is leading me.

I have installed the DataMapper gem and I have required it in my app.rb and peep.rb. I have also set up the postgres server and database.

/Users/benjamin/.rvm/gems/ruby-2.4.0/gems/dm-types-0.10.0/lib/dm-types.rb:7:in `<module:Types>': undefined method `/' for #<String:0x007fd44c8f5318> (NoMethodError)
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/dm-types-0.10.0/lib/dm-types.rb:4:in `<module:DataMapper>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/dm-types-0.10.0/lib/dm-types.rb:3:in `<top (required)>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/data_mapper-0.9.2/lib/data_mapper.rb:7:in `require'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/data_mapper-0.9.2/lib/data_mapper.rb:7:in `block in <top (required)>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/data_mapper-0.9.2/lib/data_mapper.rb:5:in `each'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/data_mapper-0.9.2/lib/data_mapper.rb:5:in `<top (required)>'
    from /Users/benjamin/Desktop/Makers/WeekFour/WeekendChallenge/chitter-challenge/app/app.rb:2:in `require'
    from /Users/benjamin/Desktop/Makers/WeekFour/WeekendChallenge/chitter-challenge/app/app.rb:2:in `<top (required)>'
    from /Users/benjamin/Desktop/Makers/WeekFour/WeekendChallenge/chitter-challenge/spec/spec_helper.rb:5:in `require'
    from /Users/benjamin/Desktop/Makers/WeekFour/WeekendChallenge/chitter-challenge/spec/spec_helper.rb:5:in `<top (required)>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1453:in `require'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1453:in `block in requires='
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1453:in `each'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1453:in `requires='
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration_options.rb:111:in `each'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration_options.rb:21:in `configure'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:99:in `setup'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:86:in `run'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/gems/rspec-core-3.6.0/exe/rspec:4:in `<top (required)>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/bin/rspec:23:in `load'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/bin/rspec:23:in `<main>'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/benjamin/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

App.rb:

require 'sinatra/base'
require 'data_mapper'
require_relative './models/peep.rb'

class Chitter < Sinatra::Base

  get '/' do
    'You arrived at the homepage'
  end

  run! if app_file == $PROGRAM_NAME
end

Peep.rb:

require 'data_mapper'
require 'dm-postgres-adapter'


class Peep

  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :text, String

end

DataMapper.setup(:default, "postgres://localhost/chitter")
DataMapper.finalize
DataMapper.auto_upgrade!

Spec_helper.rb:

require 'simplecov'
require 'simplecov-console'
require 'capybara/rspec'
require 'capybara'
require './app/app'
require './app/models/peep.rb'

Capybara.app = Chitter

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
  SimpleCov::Formatter::Console,
  # Want a nice code coverage website? Uncomment this next line!
  # SimpleCov::Formatter::HTMLFormatter
])
SimpleCov.start

RSpec.configure do |config|
  config.after(:suite) do
    puts
    puts "\e[33mHave you considered running rubocop? It will help you improve your code!\e[0m"
    puts "\e[33mTry it now! Just run: rubocop\e[0m"
  end
end

for the fellow makers who will stumble upon this error...

The solution given above did not work for me even though it gave me some hints on how to approach the issue.

So my fix was:

Check Gemfile and make sure that the datamapper version is 1.2.0

 gem 'data_mapper', '1.2.0'

then make sure that all your using gems are up to date

bundle update

I had two versions of data_mapper in my gemlock file.

I had to run the following commands:

  1. gem uninstall data_mapper

    (choose option number 3, uninstall all versions)

  2. Run Bundle

Voila. It should all work.

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