public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
shoulda / test / other / private_helpers_test.rb
100644 35 lines (30 sloc) 0.93 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require File.join(File.dirname(__FILE__), '..', 'test_helper')
 
class PrivateHelpersTest < Test::Unit::TestCase # :nodoc:
  include ThoughtBot::Shoulda::Private
  context "get_options!" do
    should "remove opts from args" do
      args = [:a, :b, {}]
      get_options!(args)
      assert_equal [:a, :b], args
    end
 
    should "return wanted opts in order" do
      args = [{:one => 1, :two => 2}]
      one, two = get_options!(args, :one, :two)
      assert_equal 1, one
      assert_equal 2, two
    end
 
    should "raise ArgumentError if given unwanted option" do
      args = [{:one => 1, :two => 2}]
      assert_raises ArgumentError do
        get_options!(args, :one)
      end
    end
  end
 
  class ::SomeModel; end
  context "model_class" do
    should "sniff the class constant from the test class" do
      self.expects(:name).returns("SomeModelTest")
      assert_equal SomeModel, model_class
    end
  end
end