cucumber-wordpress 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.rdoc +3 -3
- data/Rakefile +1 -1
- data/examples/features/support/env.rb +0 -60
- data/lib/cucumber-wordpress/steps.rb +13 -9
- data/lib/cucumber-wordpress.rb +19 -10
- metadata +3 -2
data/.gitignore
ADDED
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ Install the gem:
|
|
9
9
|
|
10
10
|
Copy the examples/features/ directory into an existing WordPress installation:
|
11
11
|
cd wordpress-installation
|
12
|
-
cp /usr/lib/ruby/gems/1.8/gems/cucumber-wordpress-1.0/examples/features .
|
12
|
+
cp -R /usr/lib/ruby/gems/1.8/gems/cucumber-wordpress-1.0/examples/features .
|
13
13
|
|
14
14
|
Configure wp-config variables:
|
15
15
|
vim features/support/config.yml
|
@@ -27,7 +27,7 @@ Run cucumber:
|
|
27
27
|
|
28
28
|
== Patches
|
29
29
|
|
30
|
-
* Send me a pull request via GitHub or
|
30
|
+
* Send me a pull request via GitHub or via email.
|
31
31
|
|
32
32
|
== Author
|
33
33
|
|
@@ -35,4 +35,4 @@ Run cucumber:
|
|
35
35
|
|
36
36
|
== Copyright
|
37
37
|
|
38
|
-
Copyright
|
38
|
+
Copyright © 2009 The Dextrous Web. See LICENCE for details.
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
2
|
require 'jeweler'
|
3
3
|
Jeweler::Tasks.new do |gem|
|
4
|
-
gem.version = "1.
|
4
|
+
gem.version = "1.1"
|
5
5
|
gem.name = "cucumber-wordpress"
|
6
6
|
gem.summary = %Q{Environment setup and step definitions for testing WordPress with Cucumber}
|
7
7
|
gem.email = "tom@thedextrousweb.com"
|
@@ -20,77 +20,17 @@ end
|
|
20
20
|
|
21
21
|
require 'cucumber-wordpress'
|
22
22
|
require 'cucumber-wordpress/steps'
|
23
|
-
|
24
|
-
# Get the WordPress configuration for this site
|
25
23
|
WordPress.configure(YAML::load(open(File.join(File.dirname(__FILE__),'config.yml'))))
|
26
|
-
|
27
|
-
# Hide the original wp-config.php, and write our own
|
28
24
|
WordPress.write_config
|
29
25
|
WordPress.create_db
|
30
|
-
|
31
26
|
at_exit do
|
32
|
-
# Replace the original wp-config.php (if it existed)
|
33
27
|
WordPress.reset_config
|
34
28
|
WordPress.drop_db
|
35
29
|
end
|
36
|
-
|
37
|
-
# Before every scenario, reset the DB to how it was when it was first installed
|
38
30
|
Before do |scenario|
|
39
31
|
WordPress.reset_db
|
40
32
|
end
|
41
33
|
|
42
34
|
#
|
43
35
|
# And we're done!
|
44
|
-
# Apart from a couple of patches we need to apply to webrat...
|
45
36
|
#
|
46
|
-
|
47
|
-
# For some reason the MechanizeAdapter uses response_body instead of response.body.
|
48
|
-
# This is needed
|
49
|
-
module Webrat
|
50
|
-
class Session
|
51
|
-
include Spec::Mocks::ExampleMethods
|
52
|
-
def response
|
53
|
-
m = mock
|
54
|
-
m.should_receive(:body).any_number_of_times.and_return(response_body)
|
55
|
-
m
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Use XPath in click_link_within, etc.
|
61
|
-
# This is needed too
|
62
|
-
module Webrat
|
63
|
-
class Scope
|
64
|
-
protected
|
65
|
-
|
66
|
-
def xpath_scoped_dom
|
67
|
-
Webrat::XML.xpath_at(@scope.dom, @selector)
|
68
|
-
end
|
69
|
-
|
70
|
-
def scoped_dom
|
71
|
-
begin
|
72
|
-
Webrat::XML.css_at(@scope.dom, @selector)
|
73
|
-
rescue Nokogiri::CSS::SyntaxError, Nokogiri::XML::XPath::SyntaxError => e
|
74
|
-
begin
|
75
|
-
# That was not a css selector, mayby it's an xpath selector?
|
76
|
-
xpath_scoped_dom
|
77
|
-
rescue
|
78
|
-
# Raise original css syntax error if selector is not xpath either
|
79
|
-
raise e
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Fix attach_file so it works with mechanize
|
87
|
-
# Thanks: https://webrat.lighthouseapp.com/projects/10503/tickets/303-tiny-patch-for-attach_file-to-work-with-mechanize
|
88
|
-
# This is not needed for cucumber-wordpress (yet)
|
89
|
-
module Webrat
|
90
|
-
class FileField < Field
|
91
|
-
protected
|
92
|
-
def test_uploaded_file
|
93
|
-
open(@value)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
Given /^WordPress is installed$/ do
|
2
2
|
visit path_to 'homepage'
|
3
3
|
title = 'A Very Boring Test Title'
|
4
|
-
if response.
|
4
|
+
if response.include? '<title>WordPress › Installation</title>'
|
5
5
|
fill_in('Blog Title', :with => title)
|
6
|
-
fill_in('Your E-mail', :with => 'test@
|
6
|
+
fill_in('Your E-mail', :with => 'test@example.org')
|
7
7
|
click_button('Install WordPress')
|
8
|
-
WordPress.passwords = {'admin' => response.
|
9
|
-
end
|
10
|
-
visit path_to 'homepage'
|
11
|
-
unless response.body.include? "<title> #{title}</title>"
|
12
|
-
raise Exception
|
8
|
+
WordPress.passwords = {'admin' => response.match(%r[<td><code>(.+)</code><br />])[1]}
|
13
9
|
end
|
10
|
+
visit path_to 'login page'
|
11
|
+
response.should include "<title>#{title} › Log In</title>"
|
14
12
|
|
15
13
|
# Take this so we can reset the DB before each scenario
|
16
14
|
WordPress.original_contents = {}
|
@@ -35,6 +33,12 @@ Given /^I am logged in as "([^\"]*)"$/ do |user|
|
|
35
33
|
click_button('Log In')
|
36
34
|
end
|
37
35
|
|
36
|
+
Given /^theme "([^\"]*)" is enabled$/ do |theme|
|
37
|
+
Given 'I am logged in as "admin"'
|
38
|
+
Given 'I am on manage themes'
|
39
|
+
click_link_within %Q&//a[contains(@title,"#{theme}")]/..&, 'Activate'
|
40
|
+
end
|
41
|
+
|
38
42
|
Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
|
39
43
|
Given 'I am logged in as "admin"'
|
40
44
|
visit path_to 'admin dashboard'
|
@@ -50,7 +54,7 @@ Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
|
|
50
54
|
end
|
51
55
|
|
52
56
|
Then /^there should be (\d+) posts?$/ do |count|
|
53
|
-
WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}posts where ID != 1 and post_type = 'post'").fetch_row.first.to_i.should == count.to_i
|
57
|
+
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
|
54
58
|
end
|
55
59
|
|
56
60
|
Then /^there should be (\d+) categories?$/ do |count|
|
@@ -67,5 +71,5 @@ Then /^there should be a post called "([^\"]*)"$/ do |post|
|
|
67
71
|
end
|
68
72
|
|
69
73
|
Then /^there should be a post called "([^\"]*)" in the "([^\"]*)" category$/ do |post, category|
|
70
|
-
WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms join #{WordPress.TABLE_PREFIX}term_relationships join #{WordPress.TABLE_PREFIX}posts where (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
|
74
|
+
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
|
71
75
|
end
|
data/lib/cucumber-wordpress.rb
CHANGED
@@ -9,10 +9,12 @@ class WordPress
|
|
9
9
|
self.instance.send(method, *args)
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_accessor :passwords, :mysql, :original_contents
|
13
|
-
attr_accessor :WEBHOST, :DB_NAME, :DB_USER, :DB_PASSWORD, :DB_HOST, :DB_CHARSET, :DB_COLLATE, :TABLE_PREFIX
|
12
|
+
attr_accessor :config, :passwords, :mysql, :original_contents
|
13
|
+
attr_accessor :ABSPATH, :WEBHOST, :DB_NAME, :DB_USER, :DB_PASSWORD, :DB_HOST, :DB_CHARSET, :DB_COLLATE, :TABLE_PREFIX
|
14
14
|
|
15
15
|
def configure(data)
|
16
|
+
@config = data
|
17
|
+
@ABSPATH = data['ABSPATH'].to_s
|
16
18
|
@WEBHOST = data['WEBHOST'].to_s
|
17
19
|
@DB_NAME = data['DB_NAME'].to_s
|
18
20
|
@DB_USER = data['DB_USER'].to_s
|
@@ -35,11 +37,11 @@ class WordPress
|
|
35
37
|
|
36
38
|
def write_config
|
37
39
|
# Copy production DB elsewhere
|
38
|
-
@has_config = File.exist? 'wp-config.php'
|
39
|
-
FileUtils.cp 'wp-config.php', '.wp-config.php' if @has_config
|
40
|
+
@has_config = File.exist? File.join(@ABSPATH,'wp-config.php')
|
41
|
+
FileUtils.cp File.join(@ABSPATH,'wp-config.php'), File.join(@ABSPATH,'.wp-config.php') if @has_config
|
40
42
|
|
41
43
|
# Write our own
|
42
|
-
open('wp-config.php','w+') do |f|
|
44
|
+
open(File.join(@ABSPATH,'wp-config.php'),'w+') do |f|
|
43
45
|
f.write <<HERE
|
44
46
|
<?php
|
45
47
|
define('DB_NAME', '#{@DB_NAME}');
|
@@ -56,8 +58,8 @@ HERE
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def reset_config
|
59
|
-
FileUtils.rm 'wp-config.php'
|
60
|
-
FileUtils.mv '.wp-config.php', 'wp-config.php' if @has_config
|
61
|
+
FileUtils.rm File.join(@ABSPATH,'wp-config.php')
|
62
|
+
FileUtils.mv File.join(@ABSPATH,'.wp-config.php'), File.join(@ABSPATH,'wp-config.php') if @has_config
|
61
63
|
end
|
62
64
|
|
63
65
|
def reset_db
|
@@ -78,12 +80,19 @@ HERE
|
|
78
80
|
'/wp-login.php'
|
79
81
|
when /^admin dashboard$/
|
80
82
|
'/wp-admin/'
|
81
|
-
when /^
|
82
|
-
'/wp-admin/
|
83
|
+
when /^new post$/
|
84
|
+
'/wp-admin/post-new.php'
|
83
85
|
when /^media library$/
|
84
86
|
"/wp-admin/upload.php"
|
87
|
+
when /^manage themes$/
|
88
|
+
'/wp-admin/themes.php'
|
89
|
+
when /^new page$/
|
90
|
+
'/wp-admin/page-new.php'
|
91
|
+
when /^post "(.+?)"$/
|
92
|
+
id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$1}"').fetch_row.first.to_i
|
93
|
+
WordPress.php("echo get_permalink(#{id})")
|
85
94
|
else
|
86
|
-
|
95
|
+
return nil
|
87
96
|
end
|
88
97
|
URI::join("http://#{@WEBHOST}/", partial)
|
89
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-wordpress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "1.
|
4
|
+
version: "1.1"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Adams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-23 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ extensions: []
|
|
51
51
|
extra_rdoc_files:
|
52
52
|
- README.rdoc
|
53
53
|
files:
|
54
|
+
- .gitignore
|
54
55
|
- LICENCE
|
55
56
|
- README.rdoc
|
56
57
|
- Rakefile
|