slacker 0.0.5 → 0.0.6
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 +33 -3
- data/bin/slacker_new +34 -0
- data/lib/slacker/application.rb +5 -1
- data/lib/slacker/rspec_ext.rb +4 -0
- data/lib/slacker/version.rb +1 -1
- data/lib/slacker_new/project/data/my_table.csv +0 -0
- data/lib/slacker_new/project/database.yml +9 -0
- data/lib/slacker_new/project/debug/failed_examples/example_001.sql +0 -0
- data/lib/slacker_new/project/debug/passed_examples/example_001.sql +0 -0
- data/lib/slacker_new/project/lib/helpers/my_helper.rb +2 -0
- data/lib/slacker_new/project/spec/sample_1.rb +70 -0
- data/lib/slacker_new/project/sql/sample_1/play_with_numbers.sql.erb +16 -0
- data/lib/slacker_new/project/sql/sample_1/sysobjects.sql.erb +1 -0
- data/lib/slacker_new/project/sql/sample_1/sysobjects_with_params.sql.erb +2 -0
- data/lib/slacker_new/project/sql/sample_1/sysobjects_with_params_2.sql.erb +5 -0
- data/slacker.gemspec +2 -2
- data/spec/rspec_ext_spec.rb +4 -32
- metadata +14 -3
- data/LICENSE +0 -3
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -7,10 +7,40 @@ __Slacker__ is a Ruby (RSpec-based) framework for developing automated tests for
|
|
7
7
|
# Install
|
8
8
|
gem install slacker
|
9
9
|
|
10
|
-
|
10
|
+
The following gems are installed automatically:
|
11
11
|
|
12
12
|
* rspec 2.5.0
|
13
13
|
* ruby-odbc 0.99994
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
__Slacker__ requires Ruby 1.9.2 running on Windows or Linux.
|
18
|
+
|
19
|
+
Before installing __Slacker__ on Windows, you need to install the [Ruby Windows Development Kit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit) (__ruby-odbc__ contains native extensions).
|
20
|
+
|
21
|
+
# Documentation TODO
|
22
|
+
|
23
|
+
Document the following features:
|
24
|
+
|
25
|
+
* Slacker project
|
26
|
+
* Project structure
|
27
|
+
* Configuration
|
28
|
+
* Running Slacker
|
29
|
+
* DSL
|
30
|
+
* SQL Templates
|
31
|
+
* Data Fixtures
|
32
|
+
* Test Matrices
|
33
|
+
* Generated SQL
|
34
|
+
* Debugging
|
35
|
+
|
36
|
+
|
37
|
+
# LICENSE
|
38
|
+
(The MIT License)
|
39
|
+
|
40
|
+
Copyright (c) 2011 Vassil Kovatchev
|
41
|
+
|
42
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/slacker_new
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
def usage
|
6
|
+
<<END
|
7
|
+
Use slacker_new to create a new Slacker project:
|
8
|
+
|
9
|
+
slacker_new <project_name>
|
10
|
+
END
|
11
|
+
end
|
12
|
+
|
13
|
+
def project_template_path
|
14
|
+
File.expand_path("#{File.dirname(__FILE__)}/../lib/slacker_new/project")
|
15
|
+
end
|
16
|
+
|
17
|
+
def slacker_new(project_name)
|
18
|
+
files = Dir.glob("#{project_template_path}/**")
|
19
|
+
FileUtils.mkdir(project_name) unless File.exist?(project_name)
|
20
|
+
FileUtils.cp_r(files, project_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def project_template_files(project_name)
|
24
|
+
files = Dir.glob("#{project_template_path}/**/*").map{|file| file.gsub(/^#{Regexp.escape(project_template_path)}\//, "./#{project_name}/")}
|
25
|
+
end
|
26
|
+
|
27
|
+
if ARGV.count != 1
|
28
|
+
puts usage
|
29
|
+
else
|
30
|
+
project_name = ARGV[0]
|
31
|
+
puts "Creating project #{project_name}..."
|
32
|
+
slacker_new(project_name)
|
33
|
+
puts project_template_files(project_name)
|
34
|
+
end
|
data/lib/slacker/application.rb
CHANGED
@@ -125,7 +125,11 @@ EOF
|
|
125
125
|
a['TDS_Version'] = '7.0' #Used by the linux driver
|
126
126
|
end
|
127
127
|
|
128
|
-
|
128
|
+
begin
|
129
|
+
@database.drvconnect(drv)
|
130
|
+
rescue ODBC::Error => e
|
131
|
+
throw_error("#{e.class}: #{e.message}")
|
132
|
+
end
|
129
133
|
end
|
130
134
|
|
131
135
|
# Run a script against the currently configured database
|
data/lib/slacker/rspec_ext.rb
CHANGED
data/lib/slacker/version.rb
CHANGED
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Database connection
|
2
|
+
# When Slacker is executed, it will attempt to connect to this database
|
3
|
+
|
4
|
+
# Replace the following with your connection information
|
5
|
+
# Note that at this point Slacker only works with SQL Server authentication
|
6
|
+
server: my_server
|
7
|
+
database: my_database
|
8
|
+
user: user_name
|
9
|
+
password: password
|
File without changes
|
File without changes
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# describe opens up an example group
|
2
|
+
describe 'My database' do
|
3
|
+
# Simple example which demonstrates inline query against the database
|
4
|
+
it 'contains system tables' do
|
5
|
+
# Select all system objects in the database
|
6
|
+
# Whe should have at least one of those
|
7
|
+
query_result = query("select * from sysobjects where xtype = 'S';")
|
8
|
+
query_result.count.should > 0
|
9
|
+
end
|
10
|
+
|
11
|
+
# The same query, this time using a SQL template
|
12
|
+
# See file sql/sample_1/sysobject.sql.erb
|
13
|
+
it 'contains system tables (take two)' do
|
14
|
+
# Every sub-folder of the sql folder appears as an sql object
|
15
|
+
# and every *.sql.erb file within sql or an sql subfolder appears as a method of this object
|
16
|
+
# At the root of all sql objects is the sql folder accessible through the "sql" object
|
17
|
+
query_result = sql.sample_1.sysobjects
|
18
|
+
query_result.count.should > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
# This time we'll use a parameterized template
|
22
|
+
# See file sql/sample_1/sysobject_with_params.sql.erb
|
23
|
+
it 'contains system tables (take three)' do
|
24
|
+
# Every file with extension .sql.erb located in the sql folder, becomes a method of object sql
|
25
|
+
query_result = sql.sample_1.sysobjects_with_params(:xtype => 'S')
|
26
|
+
query_result.count.should > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
# Let's create a table and count our user objects which match this table name
|
30
|
+
# We should get one
|
31
|
+
it 'contains a user table when one is created' do
|
32
|
+
# Use inline query to create the table
|
33
|
+
query('create table MyTable(id int, name varchar(100));')
|
34
|
+
|
35
|
+
# Now lookup the table by type and name using a more elaborate dynamic SQL template
|
36
|
+
# See template sql/sample_1/sysobject_with_params_2.sql.erb
|
37
|
+
query_result = sql.sample_1.sysobjects_with_params_2(:xtype => 'U', :name => 'MyTable')
|
38
|
+
query_result.count.should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
# SQL Templates can contain multiple statements and can return multiple resultsets
|
42
|
+
it 'can play with numbers' do
|
43
|
+
# Note that we're calling the template with a block
|
44
|
+
# When called with a block, a template is executed and its result is accessible
|
45
|
+
# from within the block through the "results" object
|
46
|
+
sql.sample_1.play_with_numbers(:x => 2, :y => 12) do
|
47
|
+
# The results object contains an array of all the resultsets generated by the query script
|
48
|
+
first_resultset = results[0]
|
49
|
+
|
50
|
+
# A resultset contains an array of records
|
51
|
+
# Each record is a hash of field => value pairs
|
52
|
+
first_resultset[0][:product].should == 24
|
53
|
+
|
54
|
+
# A resultset can be matched directly against an array of hashes
|
55
|
+
second_resultset = results[1]
|
56
|
+
second_resultset.should match([{:x => 2, :y => 12, :sum => 14}])
|
57
|
+
|
58
|
+
# Of course this works too
|
59
|
+
results[1].should match([{:x => 2, :y => 12, :sum => 14}])
|
60
|
+
|
61
|
+
# Or a resultset's values can be matched one-by-one
|
62
|
+
# Note that this resultset contains two records
|
63
|
+
third_resultset = results[2]
|
64
|
+
third_resultset[0][:p].should == 2
|
65
|
+
third_resultset[0][:s].should == 34
|
66
|
+
third_resultset[1][:p].should == 12
|
67
|
+
third_resultset[1][:s].should == 44
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
declare @x int;
|
2
|
+
declare @y int;
|
3
|
+
|
4
|
+
set @x = <%= options[:x]%>;
|
5
|
+
set @y = <%= options[:y]%>;
|
6
|
+
|
7
|
+
-- Return just the product of @x and @y
|
8
|
+
select @x * @y [product] union all
|
9
|
+
select 12;
|
10
|
+
|
11
|
+
-- Return the numbers and their sum
|
12
|
+
select @x x, @y y, @x + @y [sum];
|
13
|
+
|
14
|
+
-- Get the two numbers in one column and their sum with 32 in another
|
15
|
+
select @x p, @x + 32 s union all
|
16
|
+
select @y p, @y + 32 s;
|
@@ -0,0 +1 @@
|
|
1
|
+
select * from sysobjects where xtype = 'S';
|
data/slacker.gemspec
CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.rubyforge_project = "slacker"
|
15
15
|
|
16
|
-
s.files = ['
|
16
|
+
s.files = ['README.markdown', 'Rakefile', 'Gemfile', 'slacker.gemspec', 'Gemfile.lock'] + Dir.glob("{bin,lib,spec}/**/*")
|
17
17
|
s.test_files = Dir.glob("spec/**/*")
|
18
|
-
s.executables = ['slacker']
|
18
|
+
s.executables = ['slacker', 'slacker_new']
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.required_ruby_version = '>= 1.9.2'
|
data/spec/rspec_ext_spec.rb
CHANGED
@@ -39,6 +39,10 @@ describe Slacker::RSpecExt do
|
|
39
39
|
@instance.should respond_to(:result)
|
40
40
|
end
|
41
41
|
|
42
|
+
it 'responds to results' do
|
43
|
+
@instance.should respond_to(:results)
|
44
|
+
end
|
45
|
+
|
42
46
|
it 'responds to sql' do
|
43
47
|
@instance.should respond_to(:sql)
|
44
48
|
end
|
@@ -84,37 +88,5 @@ describe Slacker::RSpecExt do
|
|
84
88
|
@instance.sql.nest.example_1.respond_to?(:helper_1).should be_true
|
85
89
|
@instance.sql.nest.example_1.helper_1.should == 'nest/example_1/helper_1.sql.erb called'
|
86
90
|
end
|
87
|
-
|
88
|
-
# context do
|
89
|
-
# before(:each) do
|
90
|
-
# # Fake the current example in the RSpec ext
|
91
|
-
# @example = OpenStruct.new :metadata => {:sql => ''}
|
92
|
-
# @instance.stub(:example).and_return(@example)
|
93
|
-
# end
|
94
|
-
#
|
95
|
-
# specify "with files from the current example's file folder taking priority over the helpers folder" do
|
96
|
-
# @example.metadata[:example_group] = {:file_path => SpecHelper.expand_test_files_path('test_slacker_project/spec/example_1.rb')}
|
97
|
-
# @instance.sql.respond_to?(:helper_1).should be_true
|
98
|
-
# @instance.sql.helper_1.should == 'example_1/helper_1.sql called'
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
# specify "in example group giving priority to SQL files over SQL.ERB files" do
|
102
|
-
# @example.metadata[:example_group] = {:file_path => SpecHelper.expand_test_files_path('test_slacker_project/spec/example_1.rb')}
|
103
|
-
# @instance.sql.respond_to?(:helper_2).should be_true
|
104
|
-
# @instance.sql.helper_2.should == 'example_1/helper_2.sql called'
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# specify "works with deeply nested example files reflecting their location in the lookup of SQL files in the SQL folder" do
|
108
|
-
# @example.metadata[:example_group] = {:file_path => SpecHelper.expand_test_files_path('test_slacker_project/spec/nest/example_1.rb')}
|
109
|
-
# @instance.sql.respond_to?(:helper_1).should be_true
|
110
|
-
# @instance.sql.helper_1.should == 'nest/example_1/helper_1.sql.erb called'
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# specify "falls back to the global helper when there is no matching file in the example folder" do
|
114
|
-
# @example.metadata[:example_group] = {:file_path => SpecHelper.expand_test_files_path('test_slacker_project/spec/example_1.rb')}
|
115
|
-
# @instance.sql.respond_to?(:helper_3).should be_true
|
116
|
-
# @instance.sql.helper_3.should == 'helpers/helper_3.sql called'
|
117
|
-
# end
|
118
|
-
# end
|
119
91
|
end
|
120
92
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: slacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.6
|
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-06-
|
13
|
+
date: 2011-06-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -50,18 +50,19 @@ email:
|
|
50
50
|
- vassil.kovatchev@gmail.com
|
51
51
|
executables:
|
52
52
|
- slacker
|
53
|
+
- slacker_new
|
53
54
|
extensions: []
|
54
55
|
|
55
56
|
extra_rdoc_files: []
|
56
57
|
|
57
58
|
files:
|
58
|
-
- LICENSE
|
59
59
|
- README.markdown
|
60
60
|
- Rakefile
|
61
61
|
- Gemfile
|
62
62
|
- slacker.gemspec
|
63
63
|
- Gemfile.lock
|
64
64
|
- bin/slacker
|
65
|
+
- bin/slacker_new
|
65
66
|
- lib/slacker/string_helper.rb
|
66
67
|
- lib/slacker/command_line_formatter.rb
|
67
68
|
- lib/slacker/version.rb
|
@@ -73,6 +74,16 @@ files:
|
|
73
74
|
- lib/slacker/sql.rb
|
74
75
|
- lib/slacker/application.rb
|
75
76
|
- lib/slacker.rb
|
77
|
+
- lib/slacker_new/project/lib/helpers/my_helper.rb
|
78
|
+
- lib/slacker_new/project/data/my_table.csv
|
79
|
+
- lib/slacker_new/project/debug/failed_examples/example_001.sql
|
80
|
+
- lib/slacker_new/project/debug/passed_examples/example_001.sql
|
81
|
+
- lib/slacker_new/project/sql/sample_1/sysobjects_with_params_2.sql.erb
|
82
|
+
- lib/slacker_new/project/sql/sample_1/play_with_numbers.sql.erb
|
83
|
+
- lib/slacker_new/project/sql/sample_1/sysobjects_with_params.sql.erb
|
84
|
+
- lib/slacker_new/project/sql/sample_1/sysobjects.sql.erb
|
85
|
+
- lib/slacker_new/project/spec/sample_1.rb
|
86
|
+
- lib/slacker_new/project/database.yml
|
76
87
|
- spec/rspec_ext_spec.rb
|
77
88
|
- spec/query_result_matcher_spec.rb
|
78
89
|
- spec/spec_helper.rb
|
data/LICENSE
DELETED