1

My original test for user.rb looks like this:

require "test/unit"
require "minitest/autorun"
require "rack/test"
require_relative "../lib/kimsin.rb"

ENV['RACK_ENV'] = 'test'

class UserTests < Test::Unit::TestCase
  include Rack::Test::Methods
  include Kimsin

  def app
    Sinatra::Application
  end

  def test_user
    @user = User.create :username => "barerd", :password => "abcdef"
    get "/users"
    assert_equal @user.username, "barerd"
    refute_match @user.password, "abcdef"
  end
end

The test ran and obviously failed as there was no User class. When I added the User class like below:

module Kimsin
  require "data_mapper"
  require "dm-migrations"

  DataMapper.setup :default, "sqlite:///users.db"

  class User
    include DataMapper::Resource
    include BCrypt

    property :id,       Serial
    property :username, String, :required => true
    property :password, String, :required => true
    property :salt,     String, :default => "876587349506434245565664566"
    property :crypto,   String, :default => BCrypt::Password.create password + salt
  end

  User.auto_migrate!
end

it throws a "No tests." error. Actually, not only this one but all tests throw the same error now. I suspected that this has sth to do with ruby in general, because it happened after I gem installed dm-core and at the beginning it threw an error:

"Error loading RubyGems plugin "/home/barerd/.rvm/gems/ruby-1.9.3-p125/gems/rubygems-bundler-0.2.8/lib/rubygems_plugin.rb": cannot load such file -- rubygems_bundler/rubygems_bundler_installer (LoadError)"

But when I try to run tests of other apps, they all work fine. I use rvm 1.11.6 (stable) and ruby 1.9.3p125 (2012-02-16 revision 34643) [i386-cygwin] on a windows 7 by the way. Any clue to the error?

To note, the core module file kimsin.rb is as follows:

require "sinatra"
require "erb"
require "bcrypt"
require_relative "../lib/kimsin/version"
require_relative "../lib/kimsin/user"

use Rack::Session::Pool, :expire_after => 2592000

set :session_secret, "n9c0431qt043fcwo4ponm3w5483qprutc3q9pfw3r0swaypedx2qafec2qdomvuj8cy4nawscerf"

module Kimsin
  get "/" do
    title = "Kimsin?"
    erb :index, :locals => {:title => title}
  end
end
4

0 回答 0