ule_page 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 857824e4a022e82a0cf4d7d4d616dea01ad72a23
4
+ data.tar.gz: 5b021aef48ef36da55f4e4d4c09dc7675a068908
5
+ SHA512:
6
+ metadata.gz: 41cab64b513ea09135059366027d87e6abecbc49713b0158613be2ebba0726a36980f81be1a3e2e3aa730041fdb2c7b308cadfe5843c65e681031d3e4af452a3
7
+ data.tar.gz: bf345061ef09628c9e86f8479c21a3933500cdf98d4a523689ac0e438f1d5e31bcac0de00b9a16037ba86355aae95563a578e6bf6054c100c9b16a8403950542
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tsuijy@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # source 'https://rubygems.org'
2
+ source 'https://ruby.taobao.org'
3
+
4
+ # Specify your gem's dependencies in ule_page.gemspec
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,181 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ule_page (0.0.1)
5
+ activerecord
6
+ activesupport
7
+ capybara
8
+ capybara-webkit
9
+ rspec (~> 3.0)
10
+ site_prism
11
+
12
+ GEM
13
+ remote: https://ruby.taobao.org/
14
+ specs:
15
+ actionmailer (4.2.5.1)
16
+ actionpack (= 4.2.5.1)
17
+ actionview (= 4.2.5.1)
18
+ activejob (= 4.2.5.1)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ actionpack (4.2.5.1)
22
+ actionview (= 4.2.5.1)
23
+ activesupport (= 4.2.5.1)
24
+ rack (~> 1.6)
25
+ rack-test (~> 0.6.2)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (4.2.5.1)
29
+ activesupport (= 4.2.5.1)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 1.0, >= 1.0.5)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ activejob (4.2.5.1)
35
+ activesupport (= 4.2.5.1)
36
+ globalid (>= 0.3.0)
37
+ activemodel (4.2.5.1)
38
+ activesupport (= 4.2.5.1)
39
+ builder (~> 3.1)
40
+ activerecord (4.2.5.1)
41
+ activemodel (= 4.2.5.1)
42
+ activesupport (= 4.2.5.1)
43
+ arel (~> 6.0)
44
+ activesupport (4.2.5.1)
45
+ i18n (~> 0.7)
46
+ json (~> 1.7, >= 1.7.7)
47
+ minitest (~> 5.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
49
+ tzinfo (~> 1.1)
50
+ addressable (2.4.0)
51
+ arel (6.0.3)
52
+ builder (3.2.2)
53
+ capybara (2.5.0)
54
+ mime-types (>= 1.16)
55
+ nokogiri (>= 1.3.3)
56
+ rack (>= 1.0.0)
57
+ rack-test (>= 0.5.4)
58
+ xpath (~> 2.0)
59
+ capybara-webkit (1.7.1)
60
+ capybara (>= 2.3.0, < 2.6.0)
61
+ json
62
+ concurrent-ruby (1.0.0)
63
+ cucumber (1.3.20)
64
+ builder (>= 2.1.2)
65
+ diff-lcs (>= 1.1.3)
66
+ gherkin (~> 2.12)
67
+ multi_json (>= 1.7.5, < 2.0)
68
+ multi_test (>= 0.1.2)
69
+ diff-lcs (1.2.5)
70
+ docile (1.1.5)
71
+ erubis (2.7.0)
72
+ gherkin (2.12.2)
73
+ multi_json (~> 1.3)
74
+ globalid (0.3.6)
75
+ activesupport (>= 4.1.0)
76
+ i18n (0.7.0)
77
+ json (1.8.3)
78
+ loofah (2.0.3)
79
+ nokogiri (>= 1.5.9)
80
+ mail (2.6.3)
81
+ mime-types (>= 1.16, < 3)
82
+ mime-types (2.4.3)
83
+ mini_portile2 (2.0.0)
84
+ minitest (5.8.4)
85
+ multi_json (1.11.2)
86
+ multi_test (0.1.2)
87
+ nokogiri (1.6.7.2)
88
+ mini_portile2 (~> 2.0.0.rc2)
89
+ rack (1.6.4)
90
+ rack-test (0.6.3)
91
+ rack (>= 1.0)
92
+ rails (4.2.5.1)
93
+ actionmailer (= 4.2.5.1)
94
+ actionpack (= 4.2.5.1)
95
+ actionview (= 4.2.5.1)
96
+ activejob (= 4.2.5.1)
97
+ activemodel (= 4.2.5.1)
98
+ activerecord (= 4.2.5.1)
99
+ activesupport (= 4.2.5.1)
100
+ bundler (>= 1.3.0, < 2.0)
101
+ railties (= 4.2.5.1)
102
+ sprockets-rails
103
+ rails-deprecated_sanitizer (1.0.3)
104
+ activesupport (>= 4.2.0.alpha)
105
+ rails-dom-testing (1.0.7)
106
+ activesupport (>= 4.2.0.beta, < 5.0)
107
+ nokogiri (~> 1.6.0)
108
+ rails-deprecated_sanitizer (>= 1.0.1)
109
+ rails-html-sanitizer (1.0.3)
110
+ loofah (~> 2.0)
111
+ railties (4.2.5.1)
112
+ actionpack (= 4.2.5.1)
113
+ activesupport (= 4.2.5.1)
114
+ rake (>= 0.8.7)
115
+ thor (>= 0.18.1, < 2.0)
116
+ rake (10.5.0)
117
+ rspec (3.4.0)
118
+ rspec-core (~> 3.4.0)
119
+ rspec-expectations (~> 3.4.0)
120
+ rspec-mocks (~> 3.4.0)
121
+ rspec-core (3.4.2)
122
+ rspec-support (~> 3.4.0)
123
+ rspec-expectations (3.4.0)
124
+ diff-lcs (>= 1.2.0, < 2.0)
125
+ rspec-support (~> 3.4.0)
126
+ rspec-its (1.2.0)
127
+ rspec-core (>= 3.0.0)
128
+ rspec-expectations (>= 3.0.0)
129
+ rspec-mocks (3.4.1)
130
+ diff-lcs (>= 1.2.0, < 2.0)
131
+ rspec-support (~> 3.4.0)
132
+ rspec-rails (3.4.0)
133
+ actionpack (>= 3.0, < 4.3)
134
+ activesupport (>= 3.0, < 4.3)
135
+ railties (>= 3.0, < 4.3)
136
+ rspec-core (~> 3.4.0)
137
+ rspec-expectations (~> 3.4.0)
138
+ rspec-mocks (~> 3.4.0)
139
+ rspec-support (~> 3.4.0)
140
+ rspec-support (3.4.1)
141
+ simplecov (0.11.2)
142
+ docile (~> 1.1.0)
143
+ json (~> 1.8)
144
+ simplecov-html (~> 0.10.0)
145
+ simplecov-html (0.10.0)
146
+ site_prism (2.8)
147
+ addressable (>= 2.3.3, < 3.0)
148
+ capybara (>= 2.1, < 3.0)
149
+ sprockets (3.5.2)
150
+ concurrent-ruby (~> 1.0)
151
+ rack (> 1, < 3)
152
+ sprockets-rails (3.0.1)
153
+ actionpack (>= 4.0)
154
+ activesupport (>= 4.0)
155
+ sprockets (>= 3.0.0)
156
+ thor (0.19.1)
157
+ thread_safe (0.3.5)
158
+ tzinfo (1.2.2)
159
+ thread_safe (~> 0.1)
160
+ xpath (2.0.0)
161
+ nokogiri (~> 1.3)
162
+ yard (0.8.7.6)
163
+
164
+ PLATFORMS
165
+ ruby
166
+
167
+ DEPENDENCIES
168
+ activerecord (>= 3.0.0)
169
+ activesupport
170
+ bundler (~> 1.11)
171
+ cucumber (~> 1.3.15)
172
+ rails
173
+ rake (~> 10.0)
174
+ rspec-its (~> 1.0)
175
+ rspec-rails
176
+ simplecov
177
+ ule_page!
178
+ yard
179
+
180
+ BUNDLED WITH
181
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jeremy Cui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # UlePage
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ule_page`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ Using UlePage, you can define page model object easily. e.g.
6
+ ```ruby
7
+ module Page
8
+ module Customers
9
+ class Create < UlePage::Create
10
+ define_elements Customer
11
+
12
+ def add(customer)
13
+ fill_form customer
14
+
15
+ submit
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'ule_page'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install ule_page
38
+
39
+ ## Usage
40
+ Open your features/support/env.rb, add the following lines:
41
+ ```ruby
42
+ require 'ule_page'
43
+ UlePage.setup do |config|
44
+ end
45
+ ```
46
+ And in features/support/helper.rb, add lines:
47
+ ```ruby
48
+ include UlePage::Helper
49
+
50
+ def pg
51
+ special_maps = {
52
+ '/' => Page::Homes::Index.new # or something eles, based on your page model
53
+ }
54
+
55
+ return UlePage::ModelMatch.get_current_page_with_wait special_maps
56
+ end
57
+
58
+ ```
59
+ After that, you can define your page model.
60
+
61
+ UlePage will map crud page model automatically, say, if you have a model customer defined, the four model would be added to the map.
62
+ ```ruby
63
+ {
64
+ '/customers' => Page::Customers::Index,
65
+ '/customers/:id' => Page::Customers::Details,
66
+ '/customers/new' => Page::Customers::Create,
67
+ '/customers/:id/edit' => Page::Customers::Edit
68
+ }
69
+ ```
70
+ In cucumber step files, you can use pg.xxx, pg will get your defined model automatically via current_url.
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jerecui/ule_page. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ule_page"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,77 @@
1
+ require 'capybara'
2
+
3
+ module UlePage
4
+ module Helper
5
+
6
+ def wait_for_ajax
7
+ page.has_css?('.pace-small .pace-inactive')
8
+ # Timeout.timeout(Capybara.default_wait_time) do
9
+ # loop until finished_all_ajax_requests?
10
+ # end
11
+ end
12
+
13
+ def finished_all_ajax_requests?
14
+ page.evaluate_script('jQuery .active').zero?
15
+ end
16
+
17
+ def visit_admin_pages
18
+ visit '/admin'
19
+ end
20
+
21
+ # def signin(user)
22
+ # token = User.new_remember_token
23
+
24
+ # if need_run_javascript
25
+ # if Capybara.current_driver == :selenium
26
+ # visit_admin_pages
27
+ # page.driver.browser.manage.delete_all_cookies
28
+ # Capybara.current_session.driver.browser.manage.add_cookie :name => 'remember_token', :value => token
29
+ # else
30
+ # page.driver.set_cookie("remember_token", token)
31
+ # end
32
+ # else
33
+ # Capybara.current_session.driver.browser.set_cookie("remember_token=#{token}")
34
+ # end
35
+
36
+ # user.update_attribute(:remember_token, User.encrypt(token))
37
+ # end
38
+
39
+ def signout
40
+ browser = Capybara.current_session.driver.browser
41
+ if need_run_javascript
42
+ if Capybara.current_driver == :selenium
43
+ visit_admin_pages
44
+ browser.manage.delete_all_cookies
45
+ else
46
+ page.driver.set_cookie("remember_token", '')
47
+ end
48
+ else
49
+ if browser.respond_to?(:clear_cookies)
50
+ # Rack::MockSession
51
+ browser.clear_cookies
52
+ else
53
+ Capybara.current_session.driver.browser.set_cookie("remember_token=")
54
+ end
55
+ end
56
+ end
57
+
58
+ def need_run_javascript
59
+ Capybara.current_driver == :selenium or Capybara.current_driver == Capybara.javascript_driver
60
+ end
61
+
62
+ def confirm_alert
63
+ if page.driver.class == Capybara::Selenium::Driver
64
+ page.driver.browser.switch_to.alert.accept
65
+ elsif page.driver.class == Capybara::Webkit::Driver
66
+ sleep 1 # prevent test from failing by waiting for popup
67
+ page.driver.browser.accept_js_confirms
68
+ else
69
+ p "pressed ok"
70
+ end
71
+ end
72
+
73
+ def pause_here
74
+ STDIN.getc
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,83 @@
1
+ require 'capybara'
2
+ require 'site_prism'
3
+
4
+ module UlePage
5
+ module ModelMatch
6
+
7
+ class << self
8
+ include Capybara::DSL
9
+ def get_current_page_with_wait(special_maps = {})
10
+ page.has_css?('.pace-small .pace-inactive') if defined? page
11
+
12
+ current = get_current_page special_maps
13
+
14
+ if !current_path.nil? && current.nil?
15
+ p "current path is #{current_path}, we can not get the page model, please add it to the get_current_page map. (helper.rb)"
16
+
17
+ raise
18
+ end
19
+
20
+ current
21
+ end
22
+
23
+ def get_current_page(special_maps = {})
24
+ resources = UlePage.resource_models || []
25
+
26
+ if !UlePage.map_initialized || UlePage.special_maps.empty?
27
+ UlePage.special_maps = special_maps
28
+ UlePage.map = UlePage.special_maps
29
+
30
+ # => to generate the following
31
+ # '/customers' => Page::Customers::Index.new,
32
+ # '/customers/new' => Page::Customers::Create.new,
33
+ # '/customers/:id' => Page::Customers::Details.new,
34
+ # '/customers/:id/edit' => Page::Customers::Edit.new,
35
+ resources.each do |model|
36
+
37
+ pluralized = model.to_s.underscore.pluralize
38
+ page_module_name = model.to_s.pluralize.camelize
39
+
40
+ next unless Object.const_defined?("Page::#{page_module_name}")
41
+
42
+ page_module = Object.const_get("Page").const_get(page_module_name)
43
+ UlePage.map["/#{pluralized}"] = page_module.const_get("Index").try(:new) rescue false
44
+ UlePage.map["/#{pluralized}/new"] = page_module.const_get("Create").new rescue false
45
+ UlePage.map["/#{pluralized}/:id"] = page_module.const_get("Details").new rescue false
46
+ UlePage.map["/#{pluralized}/:id/edit"] = page_module.const_get("Edit").new rescue false
47
+ end
48
+
49
+ UlePage.map_initialized = true
50
+ end
51
+
52
+ map = UlePage.map
53
+ return nil unless current_path
54
+
55
+ current = get_model map, current_path
56
+
57
+ if current.nil? && current_path.include?('/admin/')
58
+ current = get_model map, current_path[6, current_path.length]
59
+ end
60
+
61
+ current
62
+ end
63
+
64
+ def get_model(map, path)
65
+ map[path] || try_regex_match(map, path)
66
+ end
67
+
68
+ def try_regex_match(map, path)
69
+ map.each do |k, v|
70
+ pattern = k
71
+ pattern = k.gsub(/(:\w+)/, '\w+') if k.include?(':')
72
+
73
+ regex = Regexp.new "^#{pattern}$"
74
+ if regex.match(path)
75
+ return v
76
+ end
77
+ end
78
+
79
+ nil
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,11 @@
1
+ require 'ule_page/page'
2
+
3
+ module UlePage
4
+ class Create < Page
5
+ element :create_button, 'input[type="submit"]'
6
+
7
+ def submit
8
+ self.create_button.click
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'ule_page/page'
2
+
3
+ module UlePage
4
+ class Detail < Page
5
+ end
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'ule_page/page'
2
+
3
+ module UlePage
4
+ class Index < Page
5
+ element_collection :rows, 'tbody tr'
6
+
7
+ def goto_edit
8
+ click_link_or_button '编辑'
9
+ end
10
+
11
+ protected
12
+ def key_column
13
+ ""
14
+ end
15
+
16
+ def get_row key
17
+ find_row key, self.rows
18
+ end
19
+
20
+ def get_model_row model
21
+ find_row(model[key_column], self.rows)
22
+ end
23
+
24
+ def get_model_row_anchor model, link_text
25
+ row = get_model_row(model)
26
+ raise 'can not find the row' if row.nil?
27
+ row.find(:link_or_button, link_text)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,120 @@
1
+ require 'site_prism'
2
+ require 'rspec'
3
+ require 'rspec/expectations'
4
+ require 'capybara'
5
+ require 'ule_page/site_prism_extender'
6
+ require 'ule_page/helper'
7
+ require 'active_support/inflector'
8
+
9
+ module UlePage
10
+ class Page < SitePrism::Page
11
+ include Capybara::DSL
12
+ include UlePage::Helper
13
+ extend UlePage::SitePrismExtender
14
+ include RSpec::Matchers
15
+
16
+ # e.g. is_order_detail?
17
+ def self.inherited(subclass)
18
+ method_name = "is_#{subclass.parent.name.demodulize.singularize.underscore}_#{subclass.name.demodulize.singularize.underscore}?"
19
+ subclass.send(:define_method, method_name) do
20
+ true
21
+ end
22
+ end
23
+
24
+ def open(expansion = {})
25
+ self.load expansion
26
+ self
27
+ end
28
+
29
+ # usage:
30
+ # fill_form hashtable, [:id, :name], {:id => "id2"}
31
+ # fill_form hashtable, [], {:id => "id2"}
32
+ # fill_form hashtable
33
+ # if the fields is empty, it will use all the keys of the hashtable
34
+ def fill_form(hashtable, fields = [], map = {})
35
+ fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?
36
+
37
+ fields.each do |f|
38
+ key = f
39
+ key = map[f] if map.has_key?(f)
40
+
41
+ # p "setting #{f} with #{hashtable[key.to_s]}"
42
+
43
+ send(f).send(:set, hashtable[key]) or send(f).send(:select, hashtable[key]) if self.respond_to? f.to_sym
44
+ end
45
+ end
46
+
47
+ # usage:
48
+ # check_form hashtabe, [:id, :name], {:id => "id2"}
49
+ # check_form hashtable, [], {:id => "id2"}
50
+ # check_form hashtable
51
+ # if the fields is empty, it will use all the keys of the hashtable
52
+ #
53
+ # precondition:
54
+ # there are the elements mapped to the hashtable keys.
55
+ def check_form(hashtable, fields = [], map = {})
56
+ fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?
57
+
58
+ fields.each do |f|
59
+ key = f
60
+ key = map[f] if map.has_key?(f)
61
+
62
+ if self.respond_to? f.to_sym
63
+ el_content = send(f).send(:value)
64
+
65
+ expect(el_content).to eq hashtable[key.to_s]
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+ def check_have_content(content)
72
+ page.should have_content content
73
+ end
74
+
75
+ def check_have_not_content(content)
76
+ expect(page).to have_no_content(content)
77
+ end
78
+
79
+ # usage: check_have_hashtable_content hashtable
80
+ # usage: check_have_hashtable_content hashtable, [:id, :name]
81
+ def check_have_hashtable_content(hashtable, keys = [])
82
+ keys = hashtable.keys if keys.empty?
83
+
84
+ keys.each do |k|
85
+ check_have_content hashtable[k.to_s]
86
+ end
87
+ end
88
+
89
+ def check_have_no_hashtable_content(hashtable, keys = [])
90
+ keys = hashtable.keys if keys.empty?
91
+
92
+ keys.each do |k|
93
+ check_have_not_content hashtable[k.to_s]
94
+ end
95
+ end
96
+
97
+ # usage: check_element_have_content '.nav li a', 'my brand'
98
+ def check_element_have_content(selector, content)
99
+ should have_selector(selector, text: content)
100
+ end
101
+
102
+ def check_element_have_no_content(selector, content)
103
+ should have_no_selector(selector, text: content)
104
+ end
105
+
106
+ def find_row(content, rows = nil)
107
+ rows = page.all('tr') if rows.nil?
108
+
109
+ rows.each do |r|
110
+ return r if r.has_content?(content)
111
+ end
112
+ end
113
+
114
+ def go_back
115
+ click_link_or_button '返回'
116
+ end
117
+ end
118
+
119
+
120
+ end
@@ -0,0 +1,79 @@
1
+ require 'site_prism'
2
+
3
+ module UlePage
4
+ module SitePrismExtender
5
+ include SitePrism::ElementContainer
6
+ include SitePrism
7
+
8
+ # why define this method?
9
+ # if we use the elements method directly, it will be conflicted with RSpec.Mather.BuiltIn.All.elements.
10
+ # I have not found one good method to solve the confliction.
11
+ def element_collection(collection_name, *find_args)
12
+ build collection_name, *find_args do
13
+ define_method collection_name.to_s do |*runtime_args, &element_block|
14
+ self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
15
+ page.all(*find_args)
16
+ end
17
+ end
18
+ end
19
+
20
+ # attr_accessor :attributes
21
+
22
+ # can define fields based on the model class
23
+ # usage:
24
+ # define_elements Brand
25
+ def define_elements(model_class, props = [])
26
+ attributes = model_class.new.attributes.keys
27
+
28
+ props = attributes if props.empty?
29
+ props.map! { |x| x.to_s } unless props.empty?
30
+
31
+ attributes.each do |attri|
32
+ if props.include? attri
33
+ selector = "#"+"#{class_name(model_class)}_#{attri.to_s}"
34
+
35
+ element attri, selector
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ # if you want to define the element as model1[modle2][name] whose id is "model1_model2_name"
42
+ # useage
43
+ # define Brand User
44
+ # define Brand, User, [:description]
45
+ def define_sub_elements(model_class, submodel_class, props = [])
46
+ attributes = submodel_class.new.attributes.keys
47
+
48
+ props = attributes if props.empty?
49
+ props.map! { |x| x.to_s } unless props.empty?
50
+
51
+ attributes.each do |attri|
52
+ if props.include?(attri)
53
+ selector = '#' + "#{class_name(model_class)}_#{class_name(submodel_class)}_attributes_#{attri.to_s}"
54
+
55
+ element attri, selector
56
+ end
57
+ end
58
+ end
59
+
60
+ def class_name(my_class)
61
+ my_class.name.underscore.downcase
62
+ end
63
+
64
+ # instead of the rails traditional form
65
+ # in js mode, there is no prefix before the element name
66
+ def define_elements_js(model_class, excluded_props = [])
67
+ attributes = model_class.new.attributes.keys
68
+
69
+ attributes.each do |attri|
70
+ unless excluded_props.include? attri
71
+ selector = "#"+attri
72
+ # self.class.send "element", attri.to_sym, selector
73
+ element attri, selector
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module UlePage
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ule_page.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "ule_page/version"
2
+ require 'rails'
3
+ require 'active_record'
4
+ require 'site_prism'
5
+
6
+ module UlePage
7
+ autoload :Page, 'ule_page/page'
8
+ autoload :Helper, 'ule_page/helper'
9
+ autoload :ModelMatch, 'ule_page/model_match'
10
+ autoload :SitePrismExtender, 'ule_page/site_prism_extender'
11
+
12
+ autoload :Create, 'ule_page/models/create'
13
+ autoload :Detail, 'ule_page/models/detail'
14
+ autoload :Index, 'ule_page/models/index'
15
+
16
+
17
+ mattr_accessor :resource_models
18
+ @@resource_models = []
19
+
20
+ mattr_accessor :special_maps
21
+ @@special_maps = {}
22
+
23
+ mattr_accessor :map
24
+ @@map = {}
25
+
26
+ mattr_accessor :map_initialized
27
+ @@map_initialized = false
28
+
29
+ def self.setup
30
+ UlePage::Page.send(:include, Rails.application.routes.url_helpers) if defined? Rails
31
+ UlePage::Page.send(:include, ActionView::Helpers::NumberHelper) if defined? ActionView
32
+
33
+ self.add_models
34
+
35
+ yield self
36
+ end
37
+
38
+ def self.add_models
39
+ if(defined? ActiveRecord::Base && defined? Rails)
40
+ @@resource_models = Dir["#{Rails.root}/app/models/**/*.rb"].map do |m|
41
+ m.chomp('.rb').camelize.split("::").last
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+
data/ule_page.gemspec ADDED
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ule_page/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ule_page"
8
+ spec.version = UlePage::VERSION
9
+ spec.authors = ["Jeremy Cui"]
10
+ spec.email = ["tsuijy@gmail.com"]
11
+
12
+ spec.summary = %q{ Page model for cucumber test.}
13
+ spec.description = %q{ Based on the siteprism gem, add more page methods.}
14
+ spec.homepage = "https://github.com/jerecui/ule_page"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency("activesupport")
33
+
34
+
35
+ spec.add_dependency("site_prism")
36
+ spec.add_dependency("capybara")
37
+ spec.add_dependency("capybara-webkit")
38
+ spec.add_dependency("rspec", "~> 3.0")
39
+ spec.add_dependency("activesupport")
40
+ spec.add_dependency("activerecord")
41
+
42
+ spec.add_development_dependency("rails")
43
+ spec.add_development_dependency("rspec-rails")
44
+
45
+ spec.add_development_dependency("rspec-its", "~> 1.0")
46
+ spec.add_development_dependency("cucumber", "~> 1.3.15")
47
+ spec.add_development_dependency("simplecov")
48
+ # spec.add_development_dependency("aruba")
49
+ # spec.add_development_dependency("mocha", ">= 0.12.8")
50
+ # spec.add_development_dependency("bourne")
51
+ # spec.add_development_dependency("appraisal", "~> 2.1.0")
52
+ spec.add_development_dependency("activerecord", ">= 3.0.0")
53
+ spec.add_development_dependency("yard")
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,291 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ule_page
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Cui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: site_prism
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: capybara-webkit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activerecord
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec-its
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: cucumber
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 1.3.15
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 1.3.15
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: activerecord
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 3.0.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 3.0.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: yard
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ description: " Based on the siteprism gem, add more page methods."
238
+ email:
239
+ - tsuijy@gmail.com
240
+ executables: []
241
+ extensions: []
242
+ extra_rdoc_files: []
243
+ files:
244
+ - ".gitignore"
245
+ - ".rspec"
246
+ - ".travis.yml"
247
+ - CODE_OF_CONDUCT.md
248
+ - Gemfile
249
+ - Gemfile.lock
250
+ - LICENSE
251
+ - LICENSE.txt
252
+ - README.md
253
+ - Rakefile
254
+ - bin/console
255
+ - bin/setup
256
+ - lib/ule_page.rb
257
+ - lib/ule_page/helper.rb
258
+ - lib/ule_page/model_match.rb
259
+ - lib/ule_page/models/create.rb
260
+ - lib/ule_page/models/detail.rb
261
+ - lib/ule_page/models/index.rb
262
+ - lib/ule_page/page.rb
263
+ - lib/ule_page/site_prism_extender.rb
264
+ - lib/ule_page/version.rb
265
+ - ule_page.gemspec
266
+ homepage: https://github.com/jerecui/ule_page
267
+ licenses:
268
+ - MIT
269
+ metadata: {}
270
+ post_install_message:
271
+ rdoc_options: []
272
+ require_paths:
273
+ - lib
274
+ required_ruby_version: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ required_rubygems_version: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ">="
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ requirements: []
285
+ rubyforge_project:
286
+ rubygems_version: 2.5.1
287
+ signing_key:
288
+ specification_version: 4
289
+ summary: Page model for cucumber test.
290
+ test_files: []
291
+ has_rdoc: