slacker 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +1 -1
- data/lib/slacker/version.rb +1 -1
- data/lib/slacker_new/project/data/sample_1/numbers_expected_output.csv +2 -2
- data/lib/slacker_new/project/spec/sample_1.rb +15 -41
- metadata +2 -3
- data/lib/slacker_new/project/sql/sample_1/sysobjects_with_params_2.sql.erb +0 -5
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -34,7 +34,7 @@ If all is good, you should see something like this:
|
|
34
34
|
.....
|
35
35
|
|
36
36
|
Finished in 0.05222 seconds
|
37
|
-
|
37
|
+
5 examples, 0 failures
|
38
38
|
|
39
39
|
Next, check out sample file `my_project\spec\sample_1.rb` to see the BDD specification you just executed.
|
40
40
|
|
data/lib/slacker/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
"p","s"
|
2
|
-
|
3
|
-
|
2
|
+
2,34
|
3
|
+
12,44
|
@@ -4,8 +4,7 @@ describe 'My database' do
|
|
4
4
|
it 'contains system tables' do
|
5
5
|
# Select all system objects in the database.
|
6
6
|
# We should have at least one of those.
|
7
|
-
|
8
|
-
query_result.count.should > 0
|
7
|
+
query("select * from sysobjects where xtype = 'S';").count.should > 0
|
9
8
|
end
|
10
9
|
|
11
10
|
# The same query, this time using a SQL template.
|
@@ -18,9 +17,7 @@ describe 'My database' do
|
|
18
17
|
# For example, the file sysobjects.sql.erb is located in "sql/sample_1/",
|
19
18
|
# so it is accessible like this:
|
20
19
|
# sql.sample_1.sysobjects
|
21
|
-
|
22
|
-
query_result = sql.sample_1.sysobjects
|
23
|
-
query_result.count.should > 0
|
20
|
+
sql.sample_1.sysobjects.count.should > 0
|
24
21
|
end
|
25
22
|
|
26
23
|
# This time we'll use a parameterized template.
|
@@ -28,22 +25,7 @@ describe 'My database' do
|
|
28
25
|
it 'contains system tables (take three)' do
|
29
26
|
# You can pass a hash to any SQL template - this hash becomes available to the
|
30
27
|
# template through the "options" object - see file sql/sample_1/sysobject_with_params.sql.erb as an example.
|
31
|
-
|
32
|
-
query_result.count.should > 0
|
33
|
-
end
|
34
|
-
|
35
|
-
# Let's create a table and count our user objects which match this table name.
|
36
|
-
# Every "it" (example) is executed in a transaction which is rolled back once the example is complete.
|
37
|
-
# This ensures that every example starts at the same state of the database as any other example in the spec.
|
38
|
-
# No example can ever interfere witht the results of another example.
|
39
|
-
it 'contains a user table when one is created' do
|
40
|
-
# Use inline query to create the table
|
41
|
-
query('create table MyTable(id int, name varchar(100));')
|
42
|
-
|
43
|
-
# Now lookup the table by type and name using a more elaborate dynamic SQL template.
|
44
|
-
# See template sql/sample_1/sysobject_with_params_2.sql.erb
|
45
|
-
query_result = sql.sample_1.sysobjects_with_params_2(:xtype => 'U', :name => 'MyTable')
|
46
|
-
query_result.count.should == 1
|
28
|
+
sql.sample_1.sysobjects_with_params(:xtype => 'S').count.should > 0
|
47
29
|
end
|
48
30
|
|
49
31
|
# SQL Templates can contain multiple statements and can return multiple resultsets.
|
@@ -53,37 +35,29 @@ describe 'My database' do
|
|
53
35
|
# from within the block through the "results" object.
|
54
36
|
sql.sample_1.play_with_numbers(:x => 2, :y => 12) do |results|
|
55
37
|
# The results object contains an array of all the resultsets generated by the query script.
|
56
|
-
first_resultset = results[0]
|
57
|
-
|
58
38
|
# A resultset contains an array of records.
|
59
39
|
# Each record is a hash of field => value pairs.
|
60
|
-
|
40
|
+
results[0][0][:product].should == 24
|
61
41
|
|
62
42
|
# A resultset can be matched directly against an array of hashes using the "match" method.
|
63
|
-
second_resultset = results[1]
|
64
|
-
second_resultset.should match([{:x => 2, :y => 12, :sum => 14}])
|
65
|
-
|
66
|
-
# Of course this works too:
|
67
43
|
results[1].should match([{:x => 2, :y => 12, :sum => 14}])
|
68
44
|
|
45
|
+
# Or against a CSV file stored in the data folder (see file data/sample_1/numbers_expected_output.csv)
|
46
|
+
results[2].should match('sample_1/numbers_expected_output.csv')
|
47
|
+
|
69
48
|
# Or a resultset's values can be matched one-by-one.
|
70
49
|
# Note that the third resultset contains two records:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
third_resultset[1][:s].should == 44
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# The results of a query can also be compared against the contents
|
80
|
-
# of a CSV file located in the data folder - see file data/sample_1/numbers_expected_output.csv
|
81
|
-
it 'can play with numbers (take two)' do
|
82
|
-
sql.sample_1.play_with_numbers(:x => 10, :y => 34) do |results|
|
83
|
-
results[2].should match('sample_1/numbers_expected_output.csv')
|
50
|
+
results[2][0][:p].should == 2
|
51
|
+
results[2][0][:s].should == 34
|
52
|
+
results[2][1][:p].should == 12
|
53
|
+
results[2][1][:s].should == 44
|
84
54
|
end
|
85
55
|
end
|
86
56
|
|
57
|
+
# Every "it" (example) is executed in a transaction which is rolled back once the example is complete.
|
58
|
+
# This ensures that every example starts at the same state of the database as any other example in the spec.
|
59
|
+
# No example can ever interfere witht the results of another example.
|
60
|
+
#
|
87
61
|
# CSV files can be used to load data directly into a table.
|
88
62
|
# In this example, we will create a table, populate it with data,
|
89
63
|
# calculate the exponentiation of one column based on another column
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: slacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Vassil Kovatchev
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-01 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -81,7 +81,6 @@ files:
|
|
81
81
|
- lib/slacker_new/project/debug/failed_examples/example_001.sql
|
82
82
|
- lib/slacker_new/project/debug/passed_examples/example_001.sql
|
83
83
|
- lib/slacker_new/project/sql/sample_1/my_table_on_power.sql.erb
|
84
|
-
- lib/slacker_new/project/sql/sample_1/sysobjects_with_params_2.sql.erb
|
85
84
|
- lib/slacker_new/project/sql/sample_1/play_with_numbers.sql.erb
|
86
85
|
- lib/slacker_new/project/sql/sample_1/sysobjects_with_params.sql.erb
|
87
86
|
- lib/slacker_new/project/sql/sample_1/create_my_table.sql.erb
|