开拓者和Minitest - NameError:未初始化的常量MiniTest

时间:2016-01-25 21:18:33

标签: ruby-on-rails ruby bundler minitest trailblazer

环境:

rails -v
Rails 4.2.5

ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux-gnu]

bundle list trailblazer
trailblazer-1.1.0

我正在研究Trailblazer书中的例子,我遇到了一些我不理解的情况。按照书中给出的设置,当我使用bundle rake test/concerns/ar_invoice/crud_test.rb运行特定测试时,它按预期运行。但是,如果我只是运行bundle rake test,那么我会看到它:

bundle rake test
rake aborted!
NameError: uninitialized constant MiniTest
./test/concepts/ar_invoice/crud_test.rb:1:in `<top (required)>'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
./bundle  /lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/testing.rake:8:in `block in   <top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)

文件crud_test.rb包含:

cat test/concepts/ar_invoice/crud_test.rb

class ARInvoiceCrudTest < MiniTest::Spec
  describe( "Create" ) do
    it( "persists valid" ) do
      ar_invoice = ARInvoice::Create.(
        :ar_invoice => { :invoice_number => 101,
                         :client_number => 1234
        }
      ).model

      ar_invoice.persisted?.must_equal( true )
      ar_invoice.invoice_number.must_equal( 102 )
      ar_invoice.client_number.must_equal( 5678 )
    end
  end
end

而.test / test_helper.rb看起来像这样:

cat test/test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)

require 'rails/test_help'
require 'minitest/spec'
require "minitest/autorun"

require "trailblazer/rails/test/integration"

并且env | grep RAILS_ENV不会产生任何输出。

我在设置中还缺少什么?不应该运行bundle rake test只需选择crud_test.rb文件并以相同的方式运行测试,以便在命令行上显式命名文件?

1 个答案:

答案 0 :(得分:1)

这就是答案:

当然,在每个测试文件的顶部添加class Window:NSWindow, NSComboBoxDelegate, NSTextFieldDelegate, NSDatePickerCellDelegate, NSTableViewDataSource, NSTableViewDelegate, MKMapViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegate, NSCollectionViewDelegateFlowLayout, NSTabViewDelegate, NSMenuDelegate, NSDraggingDestination { } func collectionView(collectionView: NSCollectionView, writeItemsAtIndexPaths indexPaths: Set<NSIndexPath>, toPasteboard pasteboard: NSPasteboard) -> Bool { let index = indexPaths.first!.item let url = webImageURLs[index] // array of string URLs that parallels the collection view. NSPasteboard.generalPasteboard().clearContents() NSPasteboard.generalPasteboard().declareTypes([kUTTypeText as String, kUTTypeData as String], owner: nil) NSPasteboard.generalPasteboard().setString(url, forType: (kUTTypeText as String)) NSPasteboard.generalPasteboard().setData(webImageData[index], forType: (kUTTypeData as String)) return true } // Provide small version of image being dragged to accompany mouse cursor. func collectionView(collectionView: NSCollectionView, draggingImageForItemsAtIndexPaths indexPaths: Set<NSIndexPath>, withEvent event: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage { let item = collectionView.itemAtIndex(indexPaths.first!.item) return (item?.imageView?.image)!.resizeImage(20, height: 20) } // Image is dropped on destination NSCollectionView. func collectionView(collectionView: NSCollectionView, draggingSession session: NSDraggingSession, endedAtPoint screenPoint: NSPoint, dragOperation operation: NSDragOperation) { let pasteboardItem = NSPasteboard.generalPasteboard().pasteboardItems![0] let urlString = pasteboardItem.stringForType((kUTTypeText as String)) let imageData = pasteboardItem.dataForType((kUTTypeData as String)) // destinationImages is the data source for the destination collectionView. destinationImageURLs is used to keep track of the text urls. if urlString != nil { destinationImageURLs.insert(urlString!, atIndex: 0) destinationImages.insert(NSImage(data: imageData!)!, atIndex: 0) destinationCollectionView.reloadData() let selectionRect = self.favoritesCollectionView.frameForItemAtIndex(0) destinationCollectionView.scrollRectToVisible(selectionRect) } } extension NSImage { func resizeImage(width: CGFloat, height: CGFloat) -> NSImage { let img = NSImage(size: CGSizeMake(width, height)) img.lockFocus() let ctx = NSGraphicsContext.currentContext() ctx?.imageInterpolation = .High drawInRect(NSRect(x: 0, y: 0, width: width, height: height), fromRect: NSRect(x: 0, y: 0, width: size.width, height: size.height), operation: .CompositeCopy, fraction: 1) img.unlockFocus() return img } }