neo-rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ require 'set'
4
4
  #
5
5
  # This is useful when frontend developers want to fill a page with
6
6
  # mock data. Mocks can pre-define interface for real data.
7
- #
7
+ #
8
8
  # == Usage
9
9
  #
10
10
  # app/mocks/user_mock.rb:
@@ -25,17 +25,23 @@ require 'set'
25
25
  # def sexy?
26
26
  # mock.tagged?(:sexy)
27
27
  # end
28
+ #
29
+ # def car
30
+ # mock.option(:car)
31
+ # end
28
32
  # end
29
33
  #
30
34
  # Further...
31
35
  #
32
36
  # old_man = UserMock.new(:old)
33
- # old_man.age # => 78
34
- # old_man.name # => "Uncle Bob"
37
+ # old_man.age # => 78
38
+ # old_man.name # => "Uncle Bob"
39
+ # old_man.car # => nil
35
40
  #
36
- # old_sexbomb = UserMock.new(:old, :sexy)
37
- # old_sexbomb.age # => 78
41
+ # old_sexbomb = UserMock.new(:old, :sexy, :car => CarMock.new(:porsche))
42
+ # old_sexbomb.age # => 78
38
43
  # old_sexbomb.sexy? # => true
44
+ # old_sexbomb.car # => CarMock
39
45
  #
40
46
  module Neo
41
47
  module Rails
@@ -44,12 +50,14 @@ module Neo
44
50
 
45
51
  # Initializes a Mock with optional tag list.
46
52
  def initialize(*args)
47
- @mock = MockConfig.new(args)
53
+ options = Hash === args.last ? args.pop : {}
54
+ @mock = MockConfig.new(args, options)
48
55
  end
49
56
 
50
57
  class MockConfig
51
- def initialize(args)
52
- @tags = args
58
+ def initialize(tags, options={})
59
+ @tags = tags
60
+ @options = options
53
61
  end
54
62
 
55
63
  # Returns a human readable tag list.
@@ -61,6 +69,10 @@ module Neo
61
69
  def tagged?(tag)
62
70
  @tags.include?(tag)
63
71
  end
72
+
73
+ def option(name)
74
+ @options[name]
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -1,5 +1,5 @@
1
1
  module Neo
2
2
  module Rails
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/test/mock_test.rb CHANGED
@@ -30,4 +30,21 @@ class MockTest < NeoRailsCase
30
30
  refute mock.mock.tagged?(:bar)
31
31
  end
32
32
  end
33
+
34
+ context :options do
35
+ let(:mock) { Neo::Rails::Mock.new(:tag, :opt => true, "string" => :yes) }
36
+
37
+ test "passes options" do
38
+ assert_equal true, mock.mock.option(:opt)
39
+ assert_equal :yes, mock.mock.option("string")
40
+
41
+ refute mock.mock.option("opt")
42
+ refute mock.mock.option(:unknown)
43
+ end
44
+
45
+ test "is tagged" do
46
+ assert mock.mock.tagged?(:tag)
47
+ assert_equal "Tag", mock.mock.description
48
+ end
49
+ end
33
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-05 00:00:00.000000000 Z
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake