ubiquitous 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/LICENSE +2 -2
- data/README.md +9 -1
- data/lib/ubiquitous.rb +3 -1
- data/lib/ubiquitous/base_model.rb +6 -5
- data/lib/ubiquitous/instance_tag.rb +3 -5
- data/lib/ubiquitous/model_helpers.rb +20 -9
- data/lib/ubiquitous/version.rb +3 -1
- data/spec/lib/ubiquitous/base_model_spec.rb +46 -0
- data/spec/lib/ubiquitous/model_helpers_spec.rb +44 -0
- metadata +7 -3
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
Copyright (
|
1
|
+
Copyright (c) 2012 ThoughtWorks, Inc. All rights reserved.
|
2
2
|
|
3
3
|
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:
|
4
4
|
|
5
5
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
6
|
|
7
|
-
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.
|
7
|
+
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/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
A gem to help you generate an acceptance test DSL from your application domain, which then uses Rails ActionView
|
1
|
+
A gem to help you generate an acceptance test DSL from your application domain, which then re-uses Rails ActionView mechanism of element id generation to find elements in the UI matching the object and method you have called, without any boilerplate. An example:
|
2
2
|
|
3
3
|
Say you have a rails model, called Member. Calling the following code from your test:
|
4
4
|
|
@@ -29,8 +29,16 @@ returns:
|
|
29
29
|
* add the following to your env.rb or spec_helper:
|
30
30
|
|
31
31
|
require 'ubiquitous/base_model'
|
32
|
+
|
32
33
|
require 'ubiquitous/model_helpers'
|
34
|
+
|
35
|
+
then for cucumber:
|
36
|
+
|
33
37
|
World(Ubiquitous::ModelHelpers)
|
38
|
+
|
39
|
+
and for rspec:
|
40
|
+
|
41
|
+
include Ubiquitous::ModelHelpers
|
34
42
|
|
35
43
|
|
36
44
|
|
data/lib/ubiquitous.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
# Copyright 2012 ThoughtWorks, Inc. Licensed under the MIT License
|
2
|
+
|
1
3
|
module Ubiquitous
|
2
4
|
class BaseModel
|
3
5
|
|
4
|
-
def initialize(session, index=0)
|
6
|
+
def initialize(session, index=0, model)
|
5
7
|
@session = session
|
6
|
-
@normalised_model_name =
|
7
|
-
|
8
|
-
@model = models.select { |m| @normalised_model_name == m.to_s }.first.new
|
8
|
+
@normalised_model_name = model.class.name.downcase
|
9
|
+
@model = model
|
9
10
|
@index = index
|
10
11
|
end
|
11
12
|
|
@@ -25,7 +26,7 @@ module Ubiquitous
|
|
25
26
|
|
26
27
|
def element_namespace
|
27
28
|
require 'action_view/helpers/form_helper'
|
28
|
-
ActionView::Helpers::InstanceTag.new(@normalised_model_name
|
29
|
+
ActionView::Helpers::InstanceTag.new(@normalised_model_name, @method_name, nil, nil).tag_id_with_index(@index)
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2012 ThoughtWorks, Inc. Licensed under the MIT License
|
2
|
+
|
1
3
|
module ActionView
|
2
4
|
module Helpers
|
3
5
|
|
@@ -7,11 +9,7 @@ module ActionView
|
|
7
9
|
"#{sanitized_object_name}_0_#{sanitized_method_name}"
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
def tag_id_with_index(index)
|
13
|
-
"#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
|
14
|
-
end
|
12
|
+
public :tag_id_with_index
|
15
13
|
|
16
14
|
end
|
17
15
|
|
@@ -1,20 +1,31 @@
|
|
1
|
+
# Copyright 2012 ThoughtWorks, Inc. Licensed under the MIT License
|
2
|
+
|
1
3
|
module Ubiquitous
|
2
4
|
|
3
5
|
module ModelHelpers
|
4
6
|
|
5
|
-
|
7
|
+
def self.models
|
8
|
+
Dir['app/models/**/*.rb'].map { |f| File.basename(f, '.*').camelize.constantize }
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
def self.create_classes
|
12
|
+
models.each do |model|
|
13
|
+
class_name = "#{model}Model"
|
14
|
+
Object.const_set(class_name, Class.new(BaseModel))
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
def self.create_helper_methods
|
19
|
+
create_classes
|
20
|
+
models.each do |model|
|
21
|
+
method_name = (model.to_s.downcase).to_sym
|
22
|
+
send :define_method, method_name do |index=0|
|
23
|
+
"#{model}Model".constantize.new(Capybara.current_session, index, model.new)
|
24
|
+
end
|
25
|
+
end
|
16
26
|
end
|
17
|
-
|
27
|
+
|
28
|
+
create_helper_methods
|
18
29
|
|
19
30
|
end
|
20
31
|
end
|
data/lib/ubiquitous/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ubiquitous/base_model'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_view/helpers'
|
4
|
+
|
5
|
+
describe Ubiquitous::BaseModel do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@session = mock
|
9
|
+
@instance_tag_mock = mock(ActionView::Helpers::InstanceTag)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should attempt to find an element based on model and method name" do
|
13
|
+
@session.should_receive(:find).with(:id, "member_0_surname")
|
14
|
+
@instance_tag_mock.should_receive(:tag_id_with_index).and_return("member_0_surname")
|
15
|
+
ActionView::Helpers::InstanceTag.should_receive(:new).and_return(@instance_tag_mock)
|
16
|
+
|
17
|
+
class Member
|
18
|
+
def surname
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
member = Ubiquitous::BaseModel.new(@session, 0, Member.new)
|
23
|
+
member.surname
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should throw an error if the method doesn't exist on the desired model" do
|
28
|
+
|
29
|
+
class Thingy
|
30
|
+
end
|
31
|
+
|
32
|
+
thingy = Ubiquitous::BaseModel.new(@session, 0, Thingy.new)
|
33
|
+
|
34
|
+
begin
|
35
|
+
thingy.surname
|
36
|
+
raise Exception, "this error means the expected exception wasn't thrown. oh dear."
|
37
|
+
rescue => e
|
38
|
+
e.message.should == "this method, \"surname\" doesn't exist on the Thingy model"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ubiquitous/model_helpers'
|
2
|
+
require 'ubiquitous/base_model'
|
3
|
+
|
4
|
+
describe Ubiquitous::ModelHelpers do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
class Boat
|
8
|
+
end
|
9
|
+
|
10
|
+
class Car
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after :each do
|
15
|
+
Object.send(:remove_const, :BoatModel) if Object.const_defined?(:BoatModel)
|
16
|
+
Object.send(:remove_const, :CarModel) if Object.const_defined?(:CarModel)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it "should create a new class inheriting BaseModel for every Domain object found" do
|
21
|
+
|
22
|
+
Ubiquitous::ModelHelpers.should_receive(:models).any_number_of_times.and_return([Boat, Car])
|
23
|
+
Ubiquitous::ModelHelpers.create_classes
|
24
|
+
"BoatModel".constantize.should == BoatModel
|
25
|
+
BoatModel.superclass.should == Ubiquitous::BaseModel
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should create a helper method for each model" do
|
30
|
+
Ubiquitous::ModelHelpers.should_receive(:models).any_number_of_times.and_return([Boat, Car])
|
31
|
+
Ubiquitous::ModelHelpers.create_helper_methods
|
32
|
+
Object.const_set("Capybara", Class.new)
|
33
|
+
Capybara.should_receive(:current_session).and_return(nil)
|
34
|
+
|
35
|
+
class TestClass
|
36
|
+
include(Ubiquitous::ModelHelpers)
|
37
|
+
end
|
38
|
+
|
39
|
+
TestClass.new.boat.should be_a(BoatModel)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubiquitous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-07 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "The lofty ambitions of this gem are to unify your ui test and production\n
|
15
15
|
\ code's references to its domain model, and to find elements
|
@@ -30,6 +30,8 @@ files:
|
|
30
30
|
- lib/ubiquitous/instance_tag.rb
|
31
31
|
- lib/ubiquitous/model_helpers.rb
|
32
32
|
- lib/ubiquitous/version.rb
|
33
|
+
- spec/lib/ubiquitous/base_model_spec.rb
|
34
|
+
- spec/lib/ubiquitous/model_helpers_spec.rb
|
33
35
|
- ubiquitous.gemspec
|
34
36
|
homepage: ''
|
35
37
|
licenses: []
|
@@ -55,4 +57,6 @@ rubygems_version: 1.8.17
|
|
55
57
|
signing_key:
|
56
58
|
specification_version: 3
|
57
59
|
summary: Support to generate a test DSL from your Rails domain objects
|
58
|
-
test_files:
|
60
|
+
test_files:
|
61
|
+
- spec/lib/ubiquitous/base_model_spec.rb
|
62
|
+
- spec/lib/ubiquitous/model_helpers_spec.rb
|