watirsome 0.1.0 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ #### v0.1.1
2
+
3
+ * Fixed problem when plural form of `checkbox` was `checkboxs` instead of `checkboxes`
4
+
5
+ #### v0.1.0
6
+
7
+ * Initial release
data/README.md CHANGED
@@ -1,11 +1,7 @@
1
- ## watirsome
1
+ ## watirsome [![Gem Version](https://badge.fury.io/rb/watirsome.png)](http://badge.fury.io/rb/watirsome) [![Build Status](https://secure.travis-ci.org/p0deje/watirsome.png)](http://travis-ci.org/p0deje/watirsome) [![Coverage Status](https://coveralls.io/repos/p0deje/watirsome/badge.png?branch=master)](https://coveralls.io/r/p0deje/watirsome)
2
2
 
3
3
  Pure dynamic Watir-based page object DSL.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/watirsome.png)](http://badge.fury.io/rb/watirsome)
6
- [![Build Status](https://secure.travis-ci.org/p0deje/watirsome.png)](http://travis-ci.org/p0deje/watirsome)
7
- [![Coverage Status](https://coveralls.io/repos/p0deje/watirsome/badge.png?branch=master)](https://coveralls.io/r/p0deje/watirsome)
8
-
9
5
  Inspired by [page-object](https://github.com/cheezy/page-object) and [watir-page-helper](https://github.com/alisterscott/watir-page-helper).
10
6
 
11
7
  ### Installation
@@ -115,7 +111,7 @@ class Page
115
111
  include Watirsome
116
112
 
117
113
  div :layer, class: 'layer'
118
- a :link, do |text|
114
+ a :link do |text|
119
115
  layer_div.a(text: text)
120
116
  end
121
117
  end
@@ -0,0 +1,7 @@
1
+ module Watirsome
2
+ module Errors
3
+
4
+ class CannotPluralizeError < StandardError; end
5
+
6
+ end # Errors
7
+ end # Watirsome
@@ -1,3 +1,3 @@
1
1
  module Watirsome
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end # Watirsome
data/lib/watirsome.rb CHANGED
@@ -132,10 +132,35 @@ module Watirsome
132
132
  #
133
133
  def plural?(method)
134
134
  str = method.to_s
135
- sym = method.to_sym
136
- sgl = str.sub(/s$/, '').to_sym
135
+ plr = str.to_sym
136
+ sgl = str.sub(/e?s$/, '').to_sym
137
137
 
138
- /s$/ === str && Watirsome.watir_methods.include?(sym) && Watirsome.watir_methods.include?(sgl)
138
+ /s$/ === str && Watirsome.watir_methods.include?(plr) && Watirsome.watir_methods.include?(sgl)
139
+ end
140
+
141
+ #
142
+ # Pluralizes element.
143
+ #
144
+ # @example
145
+ # Watirsome::Accessors.pluralize :div #=> :divs
146
+ # Watirsome::Accessors.pluralize :checkbox #=> :checkboxes
147
+ #
148
+ # @param [Symbol, String] method
149
+ # @return [Symbol]
150
+ # @api private
151
+ #
152
+ def pluralize(method)
153
+ str = method.to_s
154
+ # first try to pluralize with "s"
155
+ if Watirsome.watir_methods.include?(:"#{str}s")
156
+ :"#{str}s"
157
+ # now try to pluralize with "es"
158
+ elsif Watirsome.watir_methods.include?(:"#{str}es")
159
+ :"#{str}es"
160
+ else
161
+ # looks like we can't pluralize it
162
+ raise Errors::CannotPluralizeError, "Can't find plural form for #{str}!"
163
+ end
139
164
  end
140
165
 
141
166
  end # self
@@ -153,3 +178,4 @@ end # Watirsome
153
178
  require 'watir-webdriver'
154
179
  require 'watirsome/accessors'
155
180
  require 'watirsome/initializers'
181
+ require 'watirsome/errors'
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Watirsome::Errors::CannotPluralizeError do
4
+ it { should be_a(StandardError) }
5
+ end
@@ -43,7 +43,6 @@ describe Watirsome do
43
43
  end
44
44
  end
45
45
 
46
-
47
46
  describe '.watir_methods' do
48
47
  it 'returns array of watir container methods' do
49
48
  described_class.watir_methods.each do |method|
@@ -63,10 +62,14 @@ describe Watirsome do
63
62
  end
64
63
 
65
64
  describe '.plural?' do
66
- it 'returns true if watir-contained method is plural' do
65
+ it 'returns true if watir-contained method is plural with "s" ending' do
67
66
  described_class.plural?(:divs).should == true
68
67
  end
69
68
 
69
+ it 'returns true if watir-contained method is plural with "es" ending' do
70
+ described_class.plural?(:checkboxes).should == true
71
+ end
72
+
70
73
  it 'returns false if watir-contained method is singular' do
71
74
  described_class.plural?(:div).should == false
72
75
  end
@@ -75,6 +78,20 @@ describe Watirsome do
75
78
  described_class.plural?(:foo).should == false
76
79
  end
77
80
  end
81
+
82
+ describe '.pluralize' do
83
+ it 'pluralizes method name with "s"' do
84
+ described_class.pluralize(:div).should == :divs
85
+ end
86
+
87
+ it 'pluralizes method name with "es"' do
88
+ described_class.pluralize(:checkbox).should == :checkboxes
89
+ end
90
+
91
+ it 'raises error when cannot pluralizes method' do
92
+ -> { described_class.pluralize(:foo) }.should raise_error(Watirsome::Errors::CannotPluralizeError)
93
+ end
94
+ end
78
95
 
79
96
  context 'when included' do
80
97
  include_context :page
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watirsome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -115,15 +115,18 @@ extra_rdoc_files: []
115
115
  files:
116
116
  - .coveralls.yml
117
117
  - .travis.yml
118
+ - CHANGELOG.md
118
119
  - Gemfile
119
120
  - LICENSE.md
120
121
  - README.md
121
122
  - Rakefile
122
123
  - lib/watirsome.rb
123
124
  - lib/watirsome/accessors.rb
125
+ - lib/watirsome/errors.rb
124
126
  - lib/watirsome/initializers.rb
125
127
  - lib/watirsome/version.rb
126
128
  - spec/lib/watirsome/accessors_spec.rb
129
+ - spec/lib/watirsome/errors_spec.rb
127
130
  - spec/lib/watirsome/initializers_spec.rb
128
131
  - spec/lib/watirsome_spec.rb
129
132
  - spec/spec_helper.rb
@@ -148,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
151
  version: '0'
149
152
  segments:
150
153
  - 0
151
- hash: -1889377075945738142
154
+ hash: -4498272720920945447
152
155
  required_rubygems_version: !ruby/object:Gem::Requirement
153
156
  none: false
154
157
  requirements:
@@ -157,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
160
  version: '0'
158
161
  segments:
159
162
  - 0
160
- hash: -1889377075945738142
163
+ hash: -4498272720920945447
161
164
  requirements: []
162
165
  rubyforge_project:
163
166
  rubygems_version: 1.8.23
@@ -166,6 +169,7 @@ specification_version: 3
166
169
  summary: Awesome page objects with Watir
167
170
  test_files:
168
171
  - spec/lib/watirsome/accessors_spec.rb
172
+ - spec/lib/watirsome/errors_spec.rb
169
173
  - spec/lib/watirsome/initializers_spec.rb
170
174
  - spec/lib/watirsome_spec.rb
171
175
  - spec/spec_helper.rb