ubiquitous 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ubiquitous.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2012 Al Grimes
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ A gem to help you generate an acceptance test DSL from your application domain, which then uses Rails ActionView convention of element id generation to find elements in the UI matching the object and method you have called. An example:
2
+
3
+ Say you have a rails model, called Member. Calling the following code from your test:
4
+
5
+
6
+ member.first_name
7
+
8
+
9
+ would return an element on the page like so:
10
+
11
+ <input id="member_0_first_name" />
12
+
13
+
14
+ This also works for multiple instances of an object on a page:
15
+
16
+
17
+ member(1).first_name
18
+
19
+
20
+ returns:
21
+
22
+ <input id="member_1_first_name" />
23
+
24
+
25
+ ## How to use:
26
+
27
+ * add 'ubiquitous' to your gemfile
28
+ * require 'ubiquitous/instance_tag' in /config/environment.rb
29
+ * add the following to your env.rb or spec_helper:
30
+
31
+ require 'ubiquitous/base_model'
32
+ require 'ubiquitous/model_helpers'
33
+ World(Ubiquitous::ModelHelpers)
34
+
35
+
36
+
37
+
38
+
39
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/ubiquitous.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "ubiquitous/version"
2
+
3
+ module Ubiquitous
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,32 @@
1
+ module Ubiquitous
2
+ class BaseModel
3
+
4
+ def initialize(session, index=0)
5
+ @session = session
6
+ @normalised_model_name = self.class.name.gsub "Model", ""
7
+ models = Dir['app/models/**/*.rb'].map { |f| File.basename(f, '.*').camelize.constantize }
8
+ @model = models.select { |m| @normalised_model_name == m.to_s }.first.new
9
+ @index = index
10
+ end
11
+
12
+ def method_missing(method_name, *args, &block)
13
+ @method_name = method_name
14
+ assert_presence_of_method_on_model(@method_name)
15
+ @session.find(:id, element_namespace)
16
+ end
17
+
18
+ private
19
+
20
+ def assert_presence_of_method_on_model(method_name)
21
+ unless @model.public_methods.include? method_name
22
+ raise NoMethodError, "this method, \"#{method_name}\" doesn't exist on the #{@model.class.name} model"
23
+ end
24
+ end
25
+
26
+ def element_namespace
27
+ require 'action_view/helpers/form_helper'
28
+ ActionView::Helpers::InstanceTag.new(@normalised_model_name.downcase, @method_name, nil, nil).tag_id_with_index(@index)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ module ActionView
2
+ module Helpers
3
+
4
+ class InstanceTag
5
+
6
+ def tag_id
7
+ "#{sanitized_object_name}_0_#{sanitized_method_name}"
8
+ end
9
+
10
+ # No alteration, just making it public
11
+
12
+ def tag_id_with_index(index)
13
+ "#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+
@@ -0,0 +1,20 @@
1
+ module Ubiquitous
2
+
3
+ module ModelHelpers
4
+
5
+ models = Dir['app/models/**/*.rb'].map { |f| File.basename(f, '.*').camelize.constantize }
6
+
7
+ models.each do |model|
8
+ class_name = "#{model}Model"
9
+ Object.const_set(class_name, Class.new(BaseModel))
10
+ end
11
+
12
+ models.each do |model|
13
+ method_name = (model.to_s.downcase).to_sym
14
+ send :define_method, method_name do |index=0|
15
+ "#{model}Model".constantize.new(Capybara.current_session, index)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Ubiquitous
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ubiquitous/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ubiquitous"
7
+ s.version = Ubiquitous::VERSION
8
+ s.authors = ["algrimes"]
9
+ s.email = ["agrimes@thoughtworks.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Support to generate a test DSL from your Rails domain objects}
12
+ s.description = %q{The lofty ambitions of this gem are to unify your ui test and production
13
+ code's references to its domain model, and to find elements in your UI
14
+ that represent that model, without additional code. }
15
+
16
+ s.rubyforge_project = "ubiquitous"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubiquitous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - algrimes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-06 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: ! "The lofty ambitions of this gem are to unify your ui test and production\n
15
+ \ code's references to its domain model, and to find elements
16
+ in your UI\n that represent that model, without additional code. "
17
+ email:
18
+ - agrimes@thoughtworks.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/ubiquitous.rb
29
+ - lib/ubiquitous/base_model.rb
30
+ - lib/ubiquitous/instance_tag.rb
31
+ - lib/ubiquitous/model_helpers.rb
32
+ - lib/ubiquitous/version.rb
33
+ - ubiquitous.gemspec
34
+ homepage: ''
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project: ubiquitous
54
+ rubygems_version: 1.8.17
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Support to generate a test DSL from your Rails domain objects
58
+ test_files: []