smart_fixtures 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a356160841c697a366507690501ca309782254a
4
- data.tar.gz: a7fc41e20be7d9096c01563fba0d892c7d49a011
3
+ metadata.gz: 9bbac8f3ec0135d48c8936a1a5f251f1dd7015f2
4
+ data.tar.gz: 019624a8efde410de89cc3fefabbfc916ba0f883
5
5
  SHA512:
6
- metadata.gz: 918f627343e2d00d8394533262373ddfff9b0854e5e2c24eab8a3394e3cc03168b3fed5315d13fcc34b189edc6533b7b8c05d9d3d25492645a6718abfa6897c6
7
- data.tar.gz: 240e04673a7ea589d5184b9d32dd499ce785f8436b25ddccaa172f402ca5d85440dda266ece101e4aa0cd9714b33a8bc2d6c5b8c8c9fb25130c5735668dc0c77
6
+ metadata.gz: 40b36b8748a1d36ec402e57151cb5a1fc680442a2b9bdd666d21d41179c67f9899024dc8d9ce407477ca36742dccdd5c277b3d80e0323e94894ce3ff20a92b87
7
+ data.tar.gz: 093cc5b8fa46d080efc41a0b97dda44c321e8440efe94e903451ef0e73be487bee2cdc08033dfac67a01c6b89d1899ca5dfd75f468e5e4e852da2cc513a94eaa
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # SmartFixtures
2
2
 
3
3
  You can define a Test Dataset in a free-form.
4
- Defined data set is useable at any time in your unit test files.
4
+ The data set is useable at any time in your unit test files.
5
5
 
6
6
  Currently, This tool only supports RSpec.
7
7
 
@@ -48,6 +48,27 @@ describe Product do
48
48
  end
49
49
  ```
50
50
 
51
+ You can use fixtures variable as a local variables like this.
52
+
53
+ ```ruby
54
+ $ vim spec/models/product.rb
55
+
56
+ SmartFixtures.define_dataset :another_example_dataset do
57
+ let(:spec_product) { FactoryGirl.create(:product, name: 'HelloTestData') }
58
+ end
59
+
60
+ describe Product do
61
+ smart_fixtures :another_example_dataset, use_fixture_variables: true
62
+
63
+ describe 'Your test case...' do
64
+ it do
65
+ product_name = spec_product.name
66
+ expect(product_name).to eq('HelloTestData')
67
+ end
68
+ end
69
+ end
70
+ ```
71
+
51
72
 
52
73
  ## Installation
53
74
 
@@ -1,4 +1,5 @@
1
1
  if defined?(RSpec)
2
+ require 'rspec/core' unless defined? RSpec.configure
2
3
  RSpec.configure do |c|
3
4
  c.extend SmartFixtures
4
5
 
@@ -6,6 +6,9 @@ class SmartFixtures::VariableSet
6
6
  end
7
7
 
8
8
  def let(variable_name, &block)
9
- @variable_set[variable_name] = block.call
9
+ value = block.call
10
+ @variable_set[variable_name] = value
11
+ self.instance_variable_set("@#{variable_name}", value)
12
+ self.class.send(:attr_reader, variable_name)
10
13
  end
11
14
  end
@@ -1,3 +1,3 @@
1
1
  module SmartFixtures
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -21,7 +21,7 @@ module SmartFixtures
21
21
  end
22
22
  end
23
23
 
24
- def smart_fixtures(*args)
24
+ def smart_fixtures(*args, use_fixture_variables: false)
25
25
  before(:all) do
26
26
  DatabaseRollbacker::Rollbacker.instance.save(:before_load_smart_fixture)
27
27
  args.each do |fixture_name|
@@ -29,11 +29,17 @@ module SmartFixtures
29
29
  SmartFixtures.fixture_variable_set[fixture_name].nil?
30
30
  raise ArgumentError.new("Fixture #{fixture_name} not found")
31
31
  end
32
- SmartFixtures
33
- .fixture_variable_set[fixture_name]
34
- .instance_eval(&SmartFixtures.fixture_set[fixture_name])
32
+ variables = SmartFixtures.fixture_variable_set[fixture_name]
33
+ variables.instance_eval(&SmartFixtures.fixture_set[fixture_name])
34
+ if use_fixture_variables
35
+ variables.variable_set.each do |k, v|
36
+ self.instance_variable_set("@#{k}", v)
37
+ self.class.send(:attr_reader, k)
38
+ end
39
+ end
35
40
  end
36
41
  end
42
+
37
43
  after(:all) do
38
44
  DatabaseRollbacker::Rollbacker.instance.rollback(:before_load_smart_fixture)
39
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinsuke Nishio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: database_rollbacker