sham 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -11,7 +11,7 @@ Lightweight flexible factories for Ruby on Rails testing.
11
11
  Create a sham file for each of your models:
12
12
 
13
13
  # in sham/user_sham.rb
14
- class Sham::UserSham < Sham::Core
14
+ class User::Sham
15
15
  def self.options
16
16
  { :name => "Sample User" }
17
17
  end
@@ -22,6 +22,11 @@ To enable Sham in a particular environment, add the following to your environmen
22
22
  config.after_initialize do
23
23
  Sham::Config.activate!
24
24
  end
25
+
26
+ To enable Sham in cucumber, add the following to your features/support/env.rb file:
27
+
28
+ require 'sham'
29
+ Sham::Config.activate!
25
30
 
26
31
  You can now "sham" your models and pass additional attributes at creation:
27
32
 
@@ -44,7 +49,7 @@ Here is an example of testing validations on an ActiveRecord::Base class using S
44
49
  end
45
50
 
46
51
  # in sham/item_sham.rb
47
- class Sham::ItemSham < Sham::Core
52
+ class Item::Sham
48
53
  def self.options
49
54
  { :quantity => 1 }
50
55
  end
@@ -68,7 +73,7 @@ Here is an example of testing validations on an ActiveRecord::Base class using S
68
73
  You can add other alternative variations to the default "sham!" functionality:
69
74
 
70
75
  # in sham/item_sham.rb
71
- class Sham::ItemSham < Sham::Core
76
+ class Item::Sham
72
77
  def self.options
73
78
  { :weight => 1.0 }
74
79
  end
@@ -88,7 +93,7 @@ These can be invoked using:
88
93
  You can nest shammed models inside others:
89
94
 
90
95
  # in sham/line_item_sham.rb
91
- class Sham::LineItemSham < Sham::Core
96
+ class LineItem::Sham
92
97
  def self.options
93
98
  { :item => Sham::Base.new(Item) }
94
99
  end
data/lib/sham.rb CHANGED
@@ -1,10 +1,4 @@
1
1
  module Sham
2
- class Core
3
- def self.options
4
- {}
5
- end
6
- end
7
-
8
2
  class Base
9
3
  attr_accessor :klass, :options
10
4
 
@@ -20,11 +14,9 @@ module Sham
20
14
 
21
15
  class Config
22
16
  def self.activate!
23
- Dir["#{RAILS_ROOT}/sham/*_sham.rb"].each{ |f| require f }
24
-
25
- Sham.constants.each do |klass|
26
- matcher = klass.match(/(.*)Sham/)
27
- matcher[1].constantize.send(:include, Sham::Methods) unless matcher.blank?
17
+ Dir["#{RAILS_ROOT}/sham/*_sham.rb"].each do |f|
18
+ require f
19
+ (File.basename(f).match(/(.*)_sham.rb/)[1]).classify.constantize.send :include, Sham::Methods
28
20
  end
29
21
  end
30
22
  end
@@ -46,7 +38,7 @@ module Sham
46
38
  end
47
39
 
48
40
  def self.add_options! klass, options = {}, options_string = "options"
49
- eval("Sham::#{klass}Sham.#{options_string}").each do |key, value|
41
+ eval("#{klass}::Sham.#{options_string}").each do |key, value|
50
42
  options[key] = Sham.parse!(value) unless options.has_key?(key)
51
43
  end
52
44
  end
data/lib/sham/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sham
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sham
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pan Thomakos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-03 00:00:00 -08:00
18
+ date: 2010-12-05 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -72,6 +72,6 @@ rubyforge_project: sham
72
72
  rubygems_version: 1.3.7
73
73
  signing_key:
74
74
  specification_version: 3
75
- summary: sham-0.1.0
75
+ summary: sham-0.2.0
76
76
  test_files: []
77
77