cucumber-wordpress 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,13 +7,18 @@ Environment setup and step definitions for testing WordPress with Cucumber.
7
7
  Install the gem:
8
8
  gem install cucumber-wordpress --source http://gemcutter.org
9
9
 
10
- Copy the examples/features/ directory into an existing WordPress installation:
11
- cd wordpress-installation
10
+ Copy the examples/features/ directory into an existing WordPress installation
11
+ (or plugin/theme):
12
+ cd wordpress-plugin
12
13
  cp -R /usr/lib/ruby/gems/1.8/gems/cucumber-wordpress-1.0/examples/features .
13
14
 
14
15
  Configure wp-config variables:
15
16
  vim features/support/config.yml
16
17
 
18
+ ABSPATH should be WordPress' ABSPATH constant (the directory where
19
+ wp-config.php is) relative to the directory you'd run cucumber in (where
20
+ features/ is).
21
+
17
22
  Run cucumber:
18
23
  cucumber
19
24
 
@@ -35,4 +40,4 @@ Run cucumber:
35
40
 
36
41
  == Copyright
37
42
 
38
- Copyright © 2009 The Dextrous Web. See LICENCE for details.
43
+ Copyright © 2009-2010 The Dextrous Web. See LICENCE for details.
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ begin
8
8
  gem.authors = ["Tom Adams"]
9
9
  gem.add_dependency "cucumber"
10
10
  gem.add_dependency "webrat"
11
+ gem.add_dependency "mechanize"
11
12
  gem.add_dependency "mysql"
12
13
  end
13
14
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
@@ -146,12 +146,7 @@ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
146
146
  end
147
147
 
148
148
  Then /^I should be on (.+)$/ do |page_name|
149
- uri = URI.parse(current_url)
150
- if uri.query.blank?
151
- uri.path.should == path_to(page_name)
152
- else
153
- "#{uri.path}?#{uri.query}".should include(path_to(page_name))
154
- end
149
+ current_url.to_s.should include(path_to(page_name).to_s)
155
150
  end
156
151
 
157
152
  Then /^show me the page$/ do
@@ -1,4 +1,5 @@
1
1
  ---
2
+ ABSPATH: ../../..
2
3
  WEBHOST: localhost
3
4
  DB_NAME: wordpress_test
4
5
  DB_USER: root
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'spec/mocks'
6
6
  require 'webrat'
7
+ require 'cucumber-wordpress/webrat-patches'
7
8
  Webrat.configure do |config|
8
9
  config.mode = :mechanize
9
10
  end
@@ -1,5 +1,5 @@
1
1
  Feature: WordPress example
2
- WordPress should be as easy to test as Rails.
2
+ WordPress should be as easy to test as Rails
3
3
 
4
4
  Background:
5
5
  Given WordPress is installed
@@ -10,9 +10,9 @@ Feature: WordPress example
10
10
  When I follow "Add New" within "#menu-posts"
11
11
  Then I should see "Add New Post"
12
12
  When I fill in "title" with "hullo thar"
13
- And I fill in "content" with "I <3 cucumber"
13
+ And I fill in "content" with "We all love WordPress."
14
14
  And I press "publish"
15
15
  Then there should be 1 post
16
16
  Given I am on homepage
17
17
  Then I should see "hullo thar"
18
- And I should see "I <3 cucumber"
18
+ And I should see "We all love WordPress."
@@ -1,12 +1,15 @@
1
1
  require 'singleton'
2
+ require 'fileutils'
3
+ require 'uri'
2
4
  require 'mysql'
3
5
  Mysql::Result.send(:include, Enumerable)
4
6
 
5
7
  class WordPress
8
+ require 'cucumber-wordpress/path_to'
6
9
  include Singleton
7
10
 
8
- def self.method_missing(method, *args)
9
- self.instance.send(method, *args)
11
+ def self.method_missing(method, *args, &block)
12
+ self.instance.send(method, *args, &block)
10
13
  end
11
14
 
12
15
  attr_accessor :config, :passwords, :original_contents, :tables
@@ -41,7 +44,7 @@ class WordPress
41
44
  end
42
45
 
43
46
  def create_db
44
- mysql.query("create database #{@DB_NAME} character set = #{@DB_CHARSET}#{@DB_COLLATE.present? ? " collate = #{@DB_COLLATE}" : ''}")
47
+ mysql.query("create database #{@DB_NAME} character set = #{@DB_CHARSET}#{@DB_COLLATE.empty? ? '' : " collate = #{@DB_COLLATE}"}")
45
48
  mysql.query("use #{@DB_NAME}")
46
49
  end
47
50
 
@@ -54,6 +57,9 @@ class WordPress
54
57
  @has_config = File.exist? File.join(@ABSPATH,'wp-config.php')
55
58
  FileUtils.cp File.join(@ABSPATH,'wp-config.php'), File.join(@ABSPATH,'.wp-config.php') if @has_config
56
59
 
60
+ extra_config = ''
61
+ yield extra_config if block_given?
62
+
57
63
  # Write our own
58
64
  open(File.join(@ABSPATH,'wp-config.php'),'w+') do |f|
59
65
  f.write <<HERE
@@ -67,6 +73,7 @@ define('DB_CHARSET', '#{@DB_CHARSET}');
67
73
  define('DB_COLLATE', '#{@DB_COLLATE}');
68
74
  $table_prefix = '#{@TABLE_PREFIX}';
69
75
  if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');
76
+ #{extra_config}
70
77
  require_once(ABSPATH . 'wp-settings.php');
71
78
  HERE
72
79
  end
@@ -87,35 +94,34 @@ HERE
87
94
  end
88
95
  end
89
96
 
90
- def path_to(page_name)
91
- partial = case page_name
92
- when /^homepage$/
93
- '/'
94
- when /^login page$/
95
- '/wp-login.php'
96
- when /^admin dashboard$/
97
- '/wp-admin/'
98
- when /^new post$/
99
- '/wp-admin/post-new.php'
100
- when /^media library$/
101
- "/wp-admin/upload.php"
102
- when /^manage themes$/
103
- '/wp-admin/themes.php'
104
- when /^new page$/
105
- '/wp-admin/page-new.php'
106
- when /^(post|page) "(.+?)"$/
107
- id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$2}"').fetch_row.first.to_i
108
- WordPress.php("echo get_permalink(#{id})")
109
- when /^edit (post|page) "(.+?)"$/
110
- id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$2}"').fetch_row.first.to_i
111
- "/wp-admin/#{$1}.php?action=edit&post=#{id}"
112
- else
113
- return nil
114
- end
115
- URI::join("http://#{@WEBHOST}/", partial)
97
+ def get_post_id(title)
98
+ WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{title}"').fetch_row.first.to_i
116
99
  end
117
100
 
118
101
  def php code
119
- `php -r 'include "#{WordPress.ABSPATH}/wp-load.php"; #{code};' 2>/dev/null`
102
+ `php -r '$_SERVER["SERVER_SOFTWARE"]=""; $_SERVER["REQUEST_URI"]="/"; include "#{WordPress.ABSPATH}/wp-load.php"; #{code};' 2>/dev/null`
103
+ end
104
+
105
+ def version
106
+ return @version if @version
107
+ @version = php 'global $wp_version; echo $wp_version;'
108
+ @version.match(/^(\d+)\.(\d+)(:?\.(\d+))?$/)
109
+ @major = $1.to_i
110
+ @minor = $2.to_i
111
+ @patch = $3.to_i
112
+ @version
113
+ end
114
+
115
+ def major
116
+ version
117
+ @major
118
+ end
119
+ def minor
120
+ version
121
+ @minor
122
+ end
123
+ def patch
124
+ version
125
+ @patch
120
126
  end
121
127
  end
@@ -0,0 +1,38 @@
1
+ class WordPress
2
+ def path_to(page_name)
3
+ partial = case page_name
4
+ when /^homepage$/
5
+ '/'
6
+ when /^login page$/
7
+ '/wp-login.php'
8
+ when /^admin dashboard$/
9
+ '/wp-admin/'
10
+ when /^new post$/
11
+ '/wp-admin/post-new.php'
12
+ when /^media library$/
13
+ "/wp-admin/upload.php"
14
+ when /^manage themes$/
15
+ '/wp-admin/themes.php'
16
+ when /^plugins$/
17
+ '/wp-admin/plugins.php'
18
+ when /^new user$/
19
+ '/wp-admin/user-new.php'
20
+ when /^new page$/
21
+ case major
22
+ when 2
23
+ '/wp-admin/page-new.php'
24
+ when 3
25
+ '/wp-admin/post-new.php?post_type=page'
26
+ else
27
+ raise
28
+ end
29
+ when /^(post|page) "(.+?)"$/
30
+ WordPress.php("echo get_permalink(#{get_post_id($2)})")
31
+ when /^edit (post|page) "(.+?)"$/
32
+ "/wp-admin/#{$1}.php?action=edit&post=#{get_post_id($2)}"
33
+ else
34
+ return nil
35
+ end
36
+ URI::join("http://#{@WEBHOST}/", partial).to_s
37
+ end
38
+ end
@@ -1,101 +1,26 @@
1
- Given /^WordPress is installed$/ do
2
- visit path_to 'homepage'
3
- title = 'A Very Boring Test Title'
4
- if response.include? '<title>WordPress &rsaquo; Installation</title>'
5
- fill_in('Blog Title', :with => title)
6
- fill_in('Your E-mail', :with => 'test@example.org')
7
- click_button('Install WordPress')
8
- WordPress.passwords = {'admin' => response.match(%r[<td><code>(.+)</code><br />])[1]}
9
- end
10
- visit path_to 'login page'
11
- response.should include "<title>#{title} &rsaquo; Log In</title>"
12
-
13
- # Take this so we can reset the DB before each scenario
14
- WordPress.original_contents = {}
15
- WordPress.tables.each do |table|
16
- WordPress.original_contents[table] = WordPress.mysql.query("select * from #{table}").map{|row|row}
17
- end
18
- end
19
-
20
- Given /^I am logged in as "([^\"]*)"$/ do |user|
21
- visit path_to 'login page'
22
- fill_in('Username', :with => user)
23
- fill_in('Password', :with => WordPress.passwords[user])
24
- click_button('Log In')
25
- end
26
-
27
- Given /^I am not logged in$/ do
28
- visit path_to 'admin dashboard'
29
- click_link('Log Out')
30
- end
31
-
32
- Given /^theme "([^\"]*)" is enabled$/ do |theme|
33
- Given 'I am logged in as "admin"'
34
- Given 'I am on manage themes'
35
- click_link_within %Q&//a[contains(@title,"#{theme}")]/..&, 'Activate'
1
+ def see? content
2
+ see_within? '.', content
36
3
  end
37
4
 
38
- Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
39
- Given 'I am logged in as "admin"'
40
- visit path_to 'admin dashboard'
41
- click_link('Plugins')
42
- link = %Q&//a[contains(@href,"#{plugin}")]&
43
- if dom.xpath("#{link}/child::text()").any?{|t|t.to_s == 'Activate'}
44
- if able == 'enabled'
45
- click_link_within("#{link}/..",'Activate')
5
+ def see_within? selector, content
6
+ within(selector) do |item|
7
+ if item.nil?
8
+ has_content? content
46
9
  else
47
- click_link_within("#{link}/..",'Deactivate')
10
+ item.dom.to_s.include? content
48
11
  end
49
12
  end
50
13
  end
51
14
 
52
- Given /^there is a (post|page) called "([^\"]*)"$/ do |post_type,title|
53
- visit path_to "new #{post_type}"
54
- fill_in 'title', :with => title
55
- click_button 'Publish'
56
- end
57
-
58
- Given /^the (post|page) "([^\"]*)" has meta "([^\"]*)" as "(.*)"$/ do |post_type,title,key,value|
59
- visit path_to %Q%edit #{post_type} "#{title}"%
60
- fill_in 'metakeyinput', :with => key
61
- fill_in 'metavalue', :with => value
62
- click_button 'Update'
63
- end
64
-
65
- Given /^the page "([^\"]*)" has template "([^\"]*)"$/ do |title,template|
66
- visit path_to %Q%edit page "#{title}"%
67
- select template, :from => 'Page Template'
68
- click_button 'Update'
69
- end
70
-
71
- Given /^permalinks are set as "([^\"]*)"$/ do |structure|
72
- visit '/wp-admin/options-permalink.php'
73
- fill_in 'permalink_structure', :with => structure
74
- click_button 'Save Changes'
75
- end
76
-
77
- Given /^option "([^\"]*)" is set to "(.*)"$/ do |option, value|
78
- WordPress.mysql.query(%Q'DELETE FROM #{WordPress.TABLE_PREFIX}options WHERE option_name="#{Mysql.escape_string option}"')
79
- WordPress.mysql.query(%Q'INSERT INTO #{WordPress.TABLE_PREFIX}options SET option_name="#{Mysql.escape_string option}", option_value="#{Mysql.escape_string value}"')
80
- end
81
-
82
- Then /^there should be (\d+) posts?$/ do |count|
83
- WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}posts where ID != 1 and post_type = 'post' and post_status != 'trash'").fetch_row.first.to_i.should == count.to_i
84
- end
85
-
86
- Then /^there should be (\d+) categories?$/ do |count|
87
- # Two initial categories, which we won't count: Uncategorized and Blogroll
88
- WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}terms where term_id > 2").fetch_row.first.to_i.should == count.to_i
89
- end
90
-
91
- Then /^there should be a category called "([^\"]*)"$/ do |category|
92
- WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms where name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}'").fetch_row.first.to_i.should == 1
93
- end
94
-
95
- Then /^there should be a post called "([^\"]*)"$/ do |post|
96
- WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}posts where post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}'").fetch_row.first.to_i.should == 1
15
+ def should_see_within selector, content
16
+ within(selector) do |item|
17
+ if item.nil?
18
+ page.should have_content content
19
+ else
20
+ item.dom.to_s.should include content
21
+ end
22
+ end
97
23
  end
98
24
 
99
- Then /^there should be a post called "([^\"]*)" in the "([^\"]*)" category$/ do |post, category|
100
- WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms join #{WordPress.TABLE_PREFIX}term_relationships join #{WordPress.TABLE_PREFIX}posts where term_id = term_taxonomy_id and ID = object_id and (post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}') and (name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}')").fetch_row.first.to_i.should == 1
101
- end
25
+ require 'cucumber-wordpress/steps/given'
26
+ require 'cucumber-wordpress/steps/should'
@@ -0,0 +1,135 @@
1
+ Given /^WordPress is installed$/ do
2
+ visit path_to 'homepage'
3
+ title = 'A Very Boring Test Title'
4
+
5
+ username = 'admin'
6
+ password = 'password'
7
+
8
+ if see_within?('//title', 'WordPress › Installation')
9
+ if see? 'Blog Title'
10
+ # WordPress 2
11
+ fill_in('Blog Title', :with => title)
12
+ fill_in('Your E-mail', :with => 'test@example.org')
13
+ uncheck('blog_public')
14
+ click_button('Install WordPress')
15
+
16
+ xpath = '/html/body/table/tr/th[text()="%s"]/../td/code/text()'
17
+ password = response.root.xpath(xpath % 'Password').to_s
18
+
19
+
20
+ elsif see? 'Site Title'
21
+ # WordPress 3
22
+ fill_in('Site Title', :with => title)
23
+
24
+ fill_in('user_name', :with => username)
25
+ # webrat puts values into blank fields, so set these manually
26
+ fill_in('admin_password', :with => password)
27
+ fill_in('admin_password2', :with => password)
28
+
29
+ fill_in('Your E-mail', :with => 'test@example.org')
30
+ uncheck('blog_public')
31
+ click_button('Install WordPress')
32
+
33
+ else
34
+ raise Exception, 'This version of WordPress is probably not supported'
35
+ end
36
+
37
+ WordPress.passwords = {username => password}
38
+
39
+ end
40
+
41
+ visit path_to 'login page'
42
+ should_see_within('//title', "#{title} › Log In")
43
+
44
+ # Take this so we can reset the DB before each scenario
45
+ WordPress.original_contents = {}
46
+ WordPress.tables.each do |table|
47
+ WordPress.original_contents[table] = WordPress.mysql.query("select * from #{table}").map{|row|row}
48
+ end
49
+ end
50
+
51
+ Given /^I am logged in as "([^\"]*)"$/ do |user|
52
+ visit path_to 'login page'
53
+
54
+ if respond_to? :find_field
55
+ # This always fails for some unknown reason
56
+ until find_field('user_login').value == user
57
+ fill_in('user_login', :with => user)
58
+ end
59
+ else
60
+ fill_in('user_login', :with => user)
61
+ end
62
+
63
+ fill_in('user_pass', :with => WordPress.passwords[user])
64
+ click_button('Log In')
65
+ end
66
+
67
+ Given /^I am not logged in$/ do
68
+ visit path_to 'admin dashboard'
69
+ click_link('Log Out')
70
+ end
71
+
72
+ Given /^theme "([^\"]*)" is enabled$/ do |theme|
73
+ Given 'I am logged in as "admin"'
74
+ Given 'I am on manage themes'
75
+ click_link_within %Q&//a[contains(@title,"#{theme}")]/..&, 'Activate'
76
+ end
77
+
78
+ Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
79
+ Given 'I am logged in as "admin"'
80
+ Given 'I am on plugins'
81
+ link = %Q&//a[contains(@href,"#{plugin}")]&
82
+ if able == 'enabled'
83
+ text = 'Activate'
84
+ else
85
+ text = 'Deactivate'
86
+ end
87
+ click_link_within "#{link}/..", text
88
+ end
89
+
90
+ Given /^there is a (post|page) called "([^\"]*)"$/ do |post_type,title|
91
+ visit path_to "new #{post_type}"
92
+ case WordPress.major
93
+ when 2
94
+ fill_in 'title', :with => title
95
+ when 3
96
+ fill_in 'post_title', :with => title
97
+ end
98
+ click_button 'Publish'
99
+ end
100
+
101
+ Given /^the (post|page) "([^\"]*)" has meta "([^\"]*)" as "(.*)"$/ do |post_type,title,key,value|
102
+ WordPress.mysql.query(%Q'INSERT INTO #{WordPress.TABLE_PREFIX}postmeta SET post_id=(SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{title}" AND post_type != "revision"), meta_key="#{Mysql.escape_string(key)}", meta_value="#{Mysql.escape_string(value)}"')
103
+ end
104
+
105
+ Given /^the page "([^\"]*)" has template "([^\"]*)"$/ do |title,template|
106
+ visit path_to %Q%edit page "#{title}"%
107
+ select template, :from => 'Page Template'
108
+ click_button 'Update'
109
+ end
110
+
111
+ Given /^permalinks are set as "([^\"]*)"$/ do |structure|
112
+ visit '/wp-admin/options-permalink.php'
113
+ fill_in 'permalink_structure', :with => structure
114
+ click_button 'Save Changes'
115
+ end
116
+
117
+ Given /^option "([^\"]*)" is set to "(.*)"$/ do |option, value|
118
+ WordPress.mysql.query(%Q'DELETE FROM #{WordPress.TABLE_PREFIX}options WHERE option_name="#{Mysql.escape_string option}"')
119
+ WordPress.mysql.query(%Q'INSERT INTO #{WordPress.TABLE_PREFIX}options SET option_name="#{Mysql.escape_string option}", option_value="#{Mysql.escape_string value}"')
120
+ end
121
+
122
+ Given /^there is a user "([^"]*)" with role "([^"]*)"$/ do |username, role|
123
+ password = username
124
+
125
+ visit path_to 'new user'
126
+
127
+ fill_in 'user_login', :with => username
128
+ fill_in 'email', :with => username+'@example.org'
129
+ fill_in 'pass1', :with => password
130
+ fill_in 'pass2', :with => password
131
+ select role.capitalize, :from => 'role'
132
+ click_button 'Add User'
133
+
134
+ WordPress.passwords.merge!({username => password})
135
+ end
@@ -0,0 +1,32 @@
1
+ Then /^plugin "([^\"]*)" should be (enabled|disabled)$/ do |plugin,able|
2
+ Given 'I am logged in as "admin"'
3
+ Given 'I am on plugins'
4
+ link = %Q&//a[contains(@href,"#{plugin}")]&
5
+ if able == 'enabled'
6
+ text = 'Deactivate'
7
+ else
8
+ text = 'Activate'
9
+ end
10
+ should_see_within "#{link}/..", text
11
+ end
12
+
13
+ Then /^there should be (\d+) posts?$/ do |count|
14
+ WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}posts where ID != 1 and post_type = 'post' and post_status != 'trash'").fetch_row.first.to_i.should == count.to_i
15
+ end
16
+
17
+ Then /^there should be (\d+) categories?$/ do |count|
18
+ # Two initial categories, which we won't count: Uncategorized and Blogroll
19
+ WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}terms where term_id > 2").fetch_row.first.to_i.should == count.to_i
20
+ end
21
+
22
+ Then /^there should be a category called "([^\"]*)"$/ do |category|
23
+ WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms where name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}'").fetch_row.first.to_i.should == 1
24
+ end
25
+
26
+ Then /^there should be a post called "([^\"]*)"$/ do |post|
27
+ WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}posts where post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}'").fetch_row.first.to_i.should == 1
28
+ end
29
+
30
+ Then /^there should be a post called "([^\"]*)" in the "([^\"]*)" category$/ do |post, category|
31
+ WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms join #{WordPress.TABLE_PREFIX}term_relationships join #{WordPress.TABLE_PREFIX}posts where term_id = term_taxonomy_id and ID = object_id and (post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}') and (name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}')").fetch_row.first.to_i.should == 1
32
+ end
@@ -0,0 +1,84 @@
1
+ #
2
+ # Let's fix a few bugs in Webrat!
3
+ #
4
+
5
+ # For some reason the MechanizeAdapter uses response_body instead of response.body.
6
+ # This is needed
7
+ module Webrat
8
+ class Session
9
+ include Spec::Mocks::ExampleMethods
10
+ def response
11
+ m = mock
12
+ m.should_receive(:body).any_number_of_times.and_return(response_body)
13
+ m
14
+ end
15
+ end
16
+ end
17
+
18
+ # Use XPath in click_link_within, etc.
19
+ # This is needed too
20
+ module Webrat
21
+ class Scope
22
+ def scoped_dom
23
+ begin
24
+ @scope.dom.css(@selector).first
25
+ rescue Nokogiri::CSS::SyntaxError => e
26
+ begin
27
+ @scope.dom.xpath(@selector).first
28
+ rescue Nokogiri::XML::XPath::SyntaxError
29
+ raise e
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # Fix attach_file so it works with mechanize
37
+ # Thanks: https://webrat.lighthouseapp.com/projects/10503/tickets/303-tiny-patch-for-attach_file-to-work-with-mechanize
38
+ # This is not needed for cucumber-wordpress (yet)
39
+ module Webrat
40
+ class FileField < Field
41
+ def test_uploaded_file
42
+ return "" if @original_value.blank?
43
+
44
+ case Webrat.configuration.mode
45
+ when :rails
46
+ if content_type
47
+ ActionController::TestUploadedFile.new(@original_value, content_type)
48
+ else
49
+ ActionController::TestUploadedFile.new(@original_value)
50
+ end
51
+ when :rack, :merb
52
+ Rack::Test::UploadedFile.new(@original_value, content_type)
53
+ when :mechanize
54
+ open(@original_value) if @original_value.present?
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # Basic auth
61
+ module Webrat
62
+ class Session
63
+ def basic_auth(user, pass)
64
+ encoded_login = ["#{user}:#{pass}"].pack("m*").gsub(/\n/, '')
65
+ header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
66
+ if Webrat.adapter_class == MechanizeAdapter
67
+ self.adapter.mechanize.auth(user, pass)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ # Redirects
74
+ module Webrat
75
+ class MechanizeAdapter
76
+ def mechanize
77
+ @mechanize ||= begin
78
+ mechanize = Mechanize.new
79
+ mechanize.redirect_ok = true
80
+ mechanize
81
+ end
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-wordpress
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Tom Adams
@@ -9,39 +14,57 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-05 00:00:00 +00:00
17
+ date: 2010-09-15 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: cucumber
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :runtime
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: webrat
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
27
42
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: mechanize
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
30
48
  requirements:
31
49
  - - ">="
32
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
33
53
  version: "0"
34
- version:
54
+ type: :runtime
55
+ version_requirements: *id003
35
56
  - !ruby/object:Gem::Dependency
36
57
  name: mysql
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
40
60
  requirements:
41
61
  - - ">="
42
62
  - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
43
65
  version: "0"
44
- version:
66
+ type: :runtime
67
+ version_requirements: *id004
45
68
  description:
46
69
  email: tom@thedextrousweb.com
47
70
  executables: []
@@ -62,7 +85,11 @@ files:
62
85
  - examples/features/support/paths.rb
63
86
  - examples/features/wordpress.feature
64
87
  - lib/cucumber-wordpress.rb
88
+ - lib/cucumber-wordpress/path_to.rb
65
89
  - lib/cucumber-wordpress/steps.rb
90
+ - lib/cucumber-wordpress/steps/given.rb
91
+ - lib/cucumber-wordpress/steps/should.rb
92
+ - lib/cucumber-wordpress/webrat-patches.rb
66
93
  has_rdoc: true
67
94
  homepage: http://github.com/dxw/cucumber-wordpress
68
95
  licenses: []
@@ -76,18 +103,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
103
  requirements:
77
104
  - - ">="
78
105
  - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
79
108
  version: "0"
80
- version:
81
109
  required_rubygems_version: !ruby/object:Gem::Requirement
82
110
  requirements:
83
111
  - - ">="
84
112
  - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
85
115
  version: "0"
86
- version:
87
116
  requirements: []
88
117
 
89
118
  rubyforge_project:
90
- rubygems_version: 1.3.3
119
+ rubygems_version: 1.3.6
91
120
  signing_key:
92
121
  specification_version: 3
93
122
  summary: Environment setup and step definitions for testing WordPress with Cucumber