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 +4 -4
- data/README.md +22 -1
- data/lib/smart_fixtures/rspec_configure.rb +1 -0
- data/lib/smart_fixtures/variable_set.rb +4 -1
- data/lib/smart_fixtures/version.rb +1 -1
- data/lib/smart_fixtures.rb +10 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bbac8f3ec0135d48c8936a1a5f251f1dd7015f2
|
4
|
+
data.tar.gz: 019624a8efde410de89cc3fefabbfc916ba0f883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|
@@ -6,6 +6,9 @@ class SmartFixtures::VariableSet
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def let(variable_name, &block)
|
9
|
-
|
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
|
data/lib/smart_fixtures.rb
CHANGED
@@ -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
|
-
|
34
|
-
|
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.
|
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-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: database_rollbacker
|