2013-05-03 1 views
1

Paperclip Documentation은 RSpec 및 Test :: Unit 용 Paperclip의 작성기를 설정하는 지침을 제공합니다. 그러나 Minitest를 설정하려고 할 때 성공하지 못했습니다 (Test :: Unit과 동일한 지침을 따랐습니다).Paperclip Miniteset 용 Matchers

누군가가 Papercips를 만들기 위해 필요한 것을 알고 있습니다. matcher가 Minitest와 함께 작동해야합니까? 나는 이것에 대한 보석을 만들었습니다

답변

1

...이 일부 사용자 지정 주장

# test_helper.rb 

require 'paperclip/matchers' 

class ActiveSupport::TestCase 
    extend Paperclip::Shoulda::Matchers 
    include Paperclip::Shoulda::Matchers 

    # ... other code 

end 

module Minitest 
    module Assertions 
    ## 
    # Passes if matcher.matches?(subject) returns true 
    # 
    # Example: 
    # 
    # def test_validations 
    #  assert_must be_valid, @user 
    # end 
    def assert_must(matcher, subject, msg = nil) 
     msg = message(msg) do 
     if matcher.respond_to? :failure_message 
      matcher.failure_message # RSpec 3.x, 1.1 
     else 
      matcher.failure_message_for_should # RSpec 2.x, 1.2 
     end 
     end 

     assert matcher.matches?(subject), msg 
    end 

    ## 
    # Facilitator to assert_must for use with minitest-spec. If no subject 
    # given, defaults to matching against the current `subject` or the 
    # instance variable `@subject`. 
    # 
    # Example: 
    # 
    # subject { Order.new } 
    # 
    # it "should have associations" do 
    #  must belong_to :account 
    #  must have_many :line_items 
    # end 
    def must(matcher, subject = @subject || subject, msg = nil) 
     assert_must matcher, subject, msg 
    end 

    ## 
    # Passes if matcher.matches?(subject) returns false 
    # 
    # Example: 
    # 
    # def test_validations 
    #  assert_wont be_valid, @user 
    # end 
    def assert_wont(matcher, subject, msg = nil) 
     msg = message(msg) do 
     if matcher.respond_to? :failure_message_when_negated # RSpec 3.x 
      matcher.failure_message_when_negated # RSpec 3.x 
     elsif matcher.respond_to? :failure_message_for_should_not 
      matcher.failure_message_for_should_not # RSpec 2.x, 1.2 
     else 
      matcher.negative_failure_message # RSpec 1.1 
     end 
     end 

     if matcher.respond_to? :does_not_match? 
     assert matcher.does_not_match?(subject), msg 
     else 
     refute matcher.matches?(subject), msg 
     end 
    end 

    ## 
    # Facilitator to assert_wont for use with minitest-spec. If no subject 
    # given, defaults to matching against the current `subject` or the 
    # instance variable `@subject`. 
    # 
    # Example: 
    # 
    # subject { User.new } 
    # 
    # it "should validate" do 
    #  wont have_valid(:email).when("foo", "[email protected]", "@bar.com") 
    # end 
    def wont(matcher, subject = @subject || subject, msg = nil) 
     assert_wont matcher, subject, msg 
    end 
    end 
end 
minitest 스펙 레일 & 나를 위해 일하고 결국