Testing 在西纳特拉,有人使用测试夹具吗?您的测试套件是如何设置的?

Testing 在西纳特拉,有人使用测试夹具吗?您的测试套件是如何设置的?,testing,sinatra,rack,Testing,Sinatra,Rack,我来自Ruby/Rails世界。我正在一个Sinatra项目上进行测试(使用Rack::Test)。我通常在测试中使用夹具。西纳特拉也有类似的说法吗 人们如何设置他们的Sinatra测试套件(基本helloworld示例除外,这是我能找到的Sinatra测试的唯一示例) 谢谢 我使用它(还有Rails.Hate YAML fixture)。ActiveRecord包括对fixture的支持,您只需在test\u helper.rb中连接它们即可 # test/test_helper.rb req

我来自Ruby/Rails世界。我正在一个Sinatra项目上进行测试(使用Rack::Test)。我通常在测试中使用夹具。西纳特拉也有类似的说法吗

人们如何设置他们的Sinatra测试套件(基本helloworld示例除外,这是我能找到的Sinatra测试的唯一示例)


谢谢

我使用它(还有Rails.Hate YAML fixture)。

ActiveRecord包括对fixture的支持,您只需在
test\u helper.rb中连接它们即可

# test/test_helper.rb
require_relative '../app'
require 'minitest/autorun'
require 'active_record'

ActiveRecord::Base.establish_connection(:test)

class ActiveSupport::TestCase
  include ActiveRecord::TestFixtures
  include ActiveRecord::TestFixtures::ClassMethods

  class << self
    def fixtures(*fixture_set_names)
      self.fixture_path = 'test/fixtures'
      super *fixture_set_names
    end
  end

  self.use_transactional_fixtures = true
  self.use_instantiated_fixtures  = false
end
我已经发布了一个演示使用Sinatra、ActiveRecord和测试夹具的示例

# test/unit/blog_test.rb
require_relative '../test_helper'

class BlogTest < ActiveSupport::TestCase
  fixtures :blogs

  def test_create
    blog = Blog.create(:name => "Rob's Writing")
    assert_equal "Rob's Writing", blog.name
  end

  def test_find
    blog = Blog.find_by_name("Jimmy's Jottings")
    assert_equal "Stuff Jimmy says", blog.tagline
  end
end
# Rakefile
require_relative './app'
require 'rake'
require 'rake/testtask'
require 'sinatra/activerecord/rake'

Rake::TestTask.new do |t|
  t.pattern = "test/**/*_test.rb"
end

task default: :test