riot_rails 0.0.1
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/MIT-LICENSE +20 -0
- data/README.markdown +16 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/lib/riot/active_record/macros.rb +79 -0
- data/lib/riot/rails.rb +2 -0
- data/rails/init.rb +1 -0
- data/riot_rails.gemspec +61 -0
- data/test/rails_root/db/schema.rb +9 -0
- data/test/should_allow_values_for_test.rb +36 -0
- data/test/should_validate_presence_of_test.rb +18 -0
- data/test/should_validate_uniqueness_of_test.rb +20 -0
- data/test/test_helper.rb +60 -0
- metadata +90 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Justin Knowlden, Thumble Monks
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Protest Rails
|
2
|
+
|
3
|
+
[Riot](http://github.com/thumblemonks/riot) macros for Rails application testing.
|
4
|
+
|
5
|
+
More to come ...
|
6
|
+
|
7
|
+
### ActiveRecord
|
8
|
+
|
9
|
+
Standard macros
|
10
|
+
|
11
|
+
* should\_validate\_presence\_of
|
12
|
+
* should\_allow\_values\_for
|
13
|
+
* should\_not\_allow\_values\_for
|
14
|
+
* should\_validate\_uniquness\_of
|
15
|
+
|
16
|
+
Yes. Replacing Shoulda macros for now. Like I said with Riot, I love Shoulda.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
task :default => [:test]
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.pattern = 'test/**/*_test.rb'
|
10
|
+
test.verbose = false
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run Flog against library (except tests)"
|
14
|
+
task :flog do
|
15
|
+
puts %x[find ./lib -name *.rb | xargs flog]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run Roodi against library (except tests)"
|
19
|
+
task :roodi do
|
20
|
+
puts %x[find ./lib -name *.rb | xargs roodi]
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Some monks like diamonds. I like gems.
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'jeweler'
|
28
|
+
Jeweler::Tasks.new do |gem|
|
29
|
+
gem.name = "riot_rails"
|
30
|
+
gem.summary = "Riot specific test support for Rails apps"
|
31
|
+
gem.description = "Riot specific test support for Rails apps. Protest the slow app."
|
32
|
+
gem.email = "gus@gusg.us"
|
33
|
+
gem.homepage = "http://github.com/thumblemonks/riot_rails"
|
34
|
+
gem.authors = ["Justin 'Gus' Knowlden"]
|
35
|
+
gem.add_development_dependency("riot", ">= 0.9.7")
|
36
|
+
gem.add_development_dependency("activerecord", ">= 2.3.2")
|
37
|
+
end
|
38
|
+
Jeweler::GemcutterTasks.new
|
39
|
+
rescue LoadError
|
40
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
41
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Riot
|
2
|
+
module ActiveRecord
|
3
|
+
module Macros
|
4
|
+
# An ActiveRecord assertion that expects to fail when a given attribute or attributes are validated
|
5
|
+
# when a nil value is provided to them.
|
6
|
+
#
|
7
|
+
# Example
|
8
|
+
# should_validate_presence_of :name
|
9
|
+
# should_validate_presence_of :name, :email
|
10
|
+
def should_validate_presence_of(*attributes)
|
11
|
+
attributes.each do |attribute|
|
12
|
+
should("require value for #{attribute}") do
|
13
|
+
get_error_from_writing_value(topic, attribute, nil)
|
14
|
+
end.exists
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# An ActiveRecord assertion that expects to pass with a given value or set of values for a given
|
19
|
+
# attribute.
|
20
|
+
#
|
21
|
+
# Example
|
22
|
+
# should_allow_values_for :email, "a@b.cd"
|
23
|
+
# should_allow_values_for :email, "a@b.cd", "e@f.gh"
|
24
|
+
def should_allow_values_for(attribute, *values)
|
25
|
+
values.each do |value|
|
26
|
+
should("allow value of \"#{value}\" for #{attribute}") do
|
27
|
+
get_error_from_writing_value(topic, attribute, value)
|
28
|
+
end.nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# An ActiveRecord assertion that expects to fail with a given value or set of values for a given
|
33
|
+
# attribute.
|
34
|
+
#
|
35
|
+
# Example
|
36
|
+
# should_not_allow_values_for :email, "a"
|
37
|
+
# should_not_allow_values_for :email, "a", "foo.bar"
|
38
|
+
def should_not_allow_values_for(attribute, *values)
|
39
|
+
values.each do |value|
|
40
|
+
should("allow value of \"#{value}\" for #{attribute}") do
|
41
|
+
get_error_from_writing_value(topic, attribute, value)
|
42
|
+
end.exists
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# An ActiveRecord assertion that expects to fail with an attribute is not valid for record because the
|
47
|
+
# value of the attribute is not unique. Requires the topic of the context to be a created record; one
|
48
|
+
# that returns false for a call to +new_record?+.
|
49
|
+
#
|
50
|
+
# Example
|
51
|
+
# should_validate_uniqueness_of :email
|
52
|
+
def should_validate_uniqueness_of(attribute)
|
53
|
+
asserts "topic is not a new record when testing uniqueness of #{attribute}" do
|
54
|
+
!topic.new_record?
|
55
|
+
end
|
56
|
+
|
57
|
+
should "require #{attribute} to be a unique value" do
|
58
|
+
copied_model = topic.class.new
|
59
|
+
copied_value = topic.read_attribute(attribute)
|
60
|
+
get_error_from_writing_value(copied_model, attribute, copied_value)
|
61
|
+
end.exists
|
62
|
+
end
|
63
|
+
end # Macros
|
64
|
+
end # ActiveRecord
|
65
|
+
|
66
|
+
module Helpers
|
67
|
+
module Situation
|
68
|
+
private
|
69
|
+
def get_error_from_writing_value(model, attribute, value)
|
70
|
+
model.write_attribute(attribute, value)
|
71
|
+
model.valid?
|
72
|
+
model.errors.on(attribute)
|
73
|
+
end
|
74
|
+
end # Situation
|
75
|
+
end # Helpers
|
76
|
+
end # Riot
|
77
|
+
|
78
|
+
Riot::Context.instance_eval { include Riot::ActiveRecord::Macros }
|
79
|
+
Riot::Situation.instance_eval { include Riot::Helpers::Situation }
|
data/lib/riot/rails.rb
ADDED
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'riot/rails' if RAILS_ENV == 'test'
|
data/riot_rails.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{riot_rails}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Justin 'Gus' Knowlden"]
|
12
|
+
s.date = %q{2009-10-11}
|
13
|
+
s.description = %q{Riot specific test support for Rails apps. Protest the slow app.}
|
14
|
+
s.email = %q{gus@gusg.us}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.markdown",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"lib/riot/active_record/macros.rb",
|
24
|
+
"lib/riot/rails.rb",
|
25
|
+
"rails/init.rb",
|
26
|
+
"riot_rails.gemspec",
|
27
|
+
"test/rails_root/db/schema.rb",
|
28
|
+
"test/should_allow_values_for_test.rb",
|
29
|
+
"test/should_validate_presence_of_test.rb",
|
30
|
+
"test/should_validate_uniqueness_of_test.rb",
|
31
|
+
"test/test_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/thumblemonks/riot_rails}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{Riot specific test support for Rails apps}
|
38
|
+
s.test_files = [
|
39
|
+
"test/rails_root/db/schema.rb",
|
40
|
+
"test/should_allow_values_for_test.rb",
|
41
|
+
"test/should_validate_presence_of_test.rb",
|
42
|
+
"test/should_validate_uniqueness_of_test.rb",
|
43
|
+
"test/test_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<riot>, [">= 0.9.7"])
|
52
|
+
s.add_development_dependency(%q<activerecord>, [">= 2.3.2"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<riot>, [">= 0.9.7"])
|
55
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<riot>, [">= 0.9.7"])
|
59
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "should_allow_values_for" do
|
4
|
+
setup_and_run_context("when attribute allows a value", 1, 0, 0) do |test_ctx|
|
5
|
+
test_ctx.setup { Room.new }
|
6
|
+
test_ctx.should_allow_values_for :email, "a@b.cd"
|
7
|
+
end
|
8
|
+
|
9
|
+
setup_and_run_context("when attribute allows multiple values", 2, 0, 0) do |test_ctx|
|
10
|
+
test_ctx.setup { Room.new }
|
11
|
+
test_ctx.should_allow_values_for :email, "a@b.cd", "e@f.gh"
|
12
|
+
end
|
13
|
+
|
14
|
+
setup_and_run_context("when attribute is provided a valid and an invalid value", 1, 1, 0) do |test_ctx|
|
15
|
+
test_ctx.setup { Room.new }
|
16
|
+
test_ctx.should_allow_values_for :email, "a", "e@f.gh"
|
17
|
+
end
|
18
|
+
end # should_allow_values_for
|
19
|
+
|
20
|
+
context "should_not_allow_values_for" do
|
21
|
+
setup_and_run_context("when attribute does not allow a value", 1, 0, 0) do |test_ctx|
|
22
|
+
test_ctx.setup { Room.new }
|
23
|
+
test_ctx.should_not_allow_values_for :email, "a"
|
24
|
+
test_ctx.assertions.each {|a| STDOUT.puts a.raised if a.errored?}
|
25
|
+
end
|
26
|
+
|
27
|
+
setup_and_run_context("when attribute does not allow multiple values", 2, 0, 0) do |test_ctx|
|
28
|
+
test_ctx.setup { Room.new }
|
29
|
+
test_ctx.should_not_allow_values_for :email, "a", "e"
|
30
|
+
end
|
31
|
+
|
32
|
+
setup_and_run_context("when attribute is provided a valid and an invalid value", 1, 1, 0) do |test_ctx|
|
33
|
+
test_ctx.setup { Room.new }
|
34
|
+
test_ctx.should_not_allow_values_for :email, "a", "e@f.gh"
|
35
|
+
end
|
36
|
+
end # should_not_allow_values_for
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "should_validate_presence_of" do
|
4
|
+
setup_and_run_context("when attribute requires presence", 1, 0, 0) do |test_ctx|
|
5
|
+
test_ctx.setup { Room.new }
|
6
|
+
test_ctx.should_validate_presence_of :location
|
7
|
+
end
|
8
|
+
|
9
|
+
setup_and_run_context("when attribute does not require presence", 0, 1, 0) do |test_ctx|
|
10
|
+
test_ctx.setup { Room.new }
|
11
|
+
test_ctx.should_validate_presence_of :contents
|
12
|
+
end
|
13
|
+
|
14
|
+
setup_and_run_context("with multiple attributes required but not valid", 2, 0, 0) do |test_ctx|
|
15
|
+
test_ctx.setup { Room.new }
|
16
|
+
test_ctx.should_validate_presence_of :foo, :bar
|
17
|
+
end
|
18
|
+
end # should_validate_presence_of
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "should_validate_uniqueness_of" do
|
4
|
+
|
5
|
+
setup_and_run_context("without a persisted record", 0, 2, 0) do |test_ctx|
|
6
|
+
test_ctx.setup { Room.new(:email => "foo@bar.baz") }
|
7
|
+
test_ctx.should_validate_uniqueness_of :email
|
8
|
+
end
|
9
|
+
|
10
|
+
setup_and_run_context("with a persisted record", 2, 0, 0) do |test_ctx|
|
11
|
+
test_ctx.setup { Room.create_with_good_data(:email => "foo@bar.baz") }
|
12
|
+
test_ctx.should_validate_uniqueness_of :email
|
13
|
+
end
|
14
|
+
|
15
|
+
setup_and_run_context("with a persisted record but not validating uniqueness", 1, 1, 0) do |test_ctx|
|
16
|
+
test_ctx.setup { Room.create_with_good_data(:email => "goo@car.caz") }
|
17
|
+
test_ctx.should_validate_uniqueness_of :foo
|
18
|
+
end
|
19
|
+
|
20
|
+
end # should_validate_presence_of
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'riot/rails'
|
3
|
+
require 'activerecord'
|
4
|
+
|
5
|
+
RAILS_ROOT = File.dirname(__FILE__) + '/rails_root'
|
6
|
+
|
7
|
+
def shhh(&block)
|
8
|
+
orig_out = $stdout
|
9
|
+
$stdout = StringIO.new
|
10
|
+
yield
|
11
|
+
$stdout = orig_out
|
12
|
+
end
|
13
|
+
|
14
|
+
# Database setup
|
15
|
+
shhh do
|
16
|
+
ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
|
17
|
+
ActiveRecord::Base.establish_connection("test")
|
18
|
+
load(File.join(RAILS_ROOT, "db", "schema.rb"))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Model definition
|
22
|
+
class Room < ActiveRecord::Base
|
23
|
+
validates_presence_of :location, :foo, :bar
|
24
|
+
validates_format_of :email, :with => /^\w+@\w+\.\w+$/
|
25
|
+
validates_uniqueness_of :email
|
26
|
+
|
27
|
+
def self.create_with_good_data(attributes={})
|
28
|
+
create!({:location => "a", :foo => "b", :bar => "c", :email => "a@b.c"}.merge(attributes))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Test refactorings
|
33
|
+
module RiotRails
|
34
|
+
module Context
|
35
|
+
def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
|
36
|
+
should("pass #{passes} test(s)") { topic.passes }.equals(passes)
|
37
|
+
should("fail #{failures} test(s)") { topic.failures }.equals(failures)
|
38
|
+
should("error on #{errors} test(s)") { topic.errors }.equals(errors)
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_with_test_context(&block)
|
42
|
+
setup do
|
43
|
+
@test_report = Riot::NilReport.new
|
44
|
+
@test_context = Riot::Context.new("test context", @test_report)
|
45
|
+
yield(@test_context)
|
46
|
+
@test_context.report
|
47
|
+
@test_report
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_and_run_context(name, *passes_failures_errors, &block)
|
52
|
+
context name do
|
53
|
+
setup_with_test_context(&block)
|
54
|
+
asserts_passes_failures_errors(*passes_failures_errors)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Riot::Context.instance_eval { include RiotRails::Context }
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riot_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin 'Gus' Knowlden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-11 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: riot
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.7
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.2
|
34
|
+
version:
|
35
|
+
description: Riot specific test support for Rails apps. Protest the slow app.
|
36
|
+
email: gus@gusg.us
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.markdown
|
43
|
+
files:
|
44
|
+
- MIT-LICENSE
|
45
|
+
- README.markdown
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- lib/riot/active_record/macros.rb
|
49
|
+
- lib/riot/rails.rb
|
50
|
+
- rails/init.rb
|
51
|
+
- riot_rails.gemspec
|
52
|
+
- test/rails_root/db/schema.rb
|
53
|
+
- test/should_allow_values_for_test.rb
|
54
|
+
- test/should_validate_presence_of_test.rb
|
55
|
+
- test/should_validate_uniqueness_of_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/thumblemonks/riot_rails
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Riot specific test support for Rails apps
|
85
|
+
test_files:
|
86
|
+
- test/rails_root/db/schema.rb
|
87
|
+
- test/should_allow_values_for_test.rb
|
88
|
+
- test/should_validate_presence_of_test.rb
|
89
|
+
- test/should_validate_uniqueness_of_test.rb
|
90
|
+
- test/test_helper.rb
|