skink 0.3.1 → 0.4.0

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.
@@ -2,8 +2,32 @@ Dir[File.dirname(__FILE__) + "/../../../spec/support/**/*.rb"].each {|f| STDOUT.
2
2
 
3
3
  require 'skink/dsl'
4
4
 
5
+ # Pretty much everything that follows gratefully borrowed from Capybara.
6
+
7
+ module Skink
8
+ module Features
9
+ def self.included(base)
10
+ base.instance_eval do
11
+ alias :background :before
12
+ alias :scenario :it
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.api_feature(*args, &block)
19
+ options = if args.last.is_a?(Hash) then args.pop else {} end
20
+ options[:skink_features] = true
21
+ options[:type] = :api
22
+ options[:caller] ||= caller
23
+ args.push(options)
24
+
25
+ describe(*args, &block)
26
+ end
27
+
5
28
  RSpec.configure do |config|
6
- config.include Skink::DSL
29
+ config.include Skink::DSL, type: :api
30
+ config.include Skink::Features, skink_features: true
7
31
 
8
32
  config.after do
9
33
  if self.class.include?(Skink::DSL)
data/lib/skink/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Skink
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -86,14 +86,27 @@ shared_examples "a REST API test language" do
86
86
  response.should_not have_header(content_type: %r{json})
87
87
  end
88
88
 
89
- it "is able to test for the presence of elements in the response body" do
89
+ it "is able to test for the presence of xml elements in the response body" do
90
90
  with_accept_header "application/xml"
91
91
  get "/xml_doc"
92
- response.should have_xpath "//foo/foo"
92
+ response.should have_xpath "//foo/bar"
93
93
  response.should_not have_xpath "//bar/foo"
94
94
  response.should have_xpath "//foo", /Some/
95
- response.should_not have_xpath "//foo", /bar/
95
+ response.should_not have_xpath "//foo/bar", /foo/
96
+ end
97
+
98
+ it "is able to test for the presence of namespaced xml elements in the response body" do
99
+ with_accept_header "application/xml"
100
+ get "/xml_doc_with_namespaces"
101
+ response.should have_xpath "//fake:foo/fake:bar", /more/
102
+
103
+ # test a pathological case that was encountered in the real world
104
+ with_accept_header "application/xml"
105
+ get "/xml_doc_with_pathological_namespaces"
106
+ response.should have_xpath "//fake:foo/fake:bar", /more/
107
+ end
96
108
 
109
+ it "is able to test for the presence of json elements in the response body" do
97
110
  with_accept_header "application/json"
98
111
  get "/json_doc"
99
112
  response.should have_jsonpath "root.foo.foo"
@@ -107,12 +120,12 @@ shared_examples "a REST API test language" do
107
120
  get "/xml_doc"
108
121
  expect {response.should have_xpath "//not/a/valid/xpath"}.to raise_error(/^expected xpath .* in .*$/)
109
122
  expect {response.should have_xpath "//root/foo", /not there/}.to raise_error(%r{^expected xpath .* with value /not there/ in .*$})
110
- expect {response.should_not have_xpath "//foo/foo"}.to raise_error(/^expected xpath .* would not be in .*/)
123
+ expect {response.should_not have_xpath "//foo/bar"}.to raise_error(/^expected xpath .* would not be in .*/)
111
124
  expect {response.should_not have_xpath "//root/foo", /Some/}.to raise_error(%r{^expected xpath .* with value /Some/ would not be in .*$})
112
125
  end
113
126
  end
114
127
 
115
- describe Skink::DSL do
128
+ describe Skink::DSL, type: :api do
116
129
  context "using rack_test" do
117
130
  it_behaves_like "a REST API test language"
118
131
  end
@@ -122,3 +135,13 @@ describe Skink::DSL do
122
135
  it_behaves_like "a REST API test language"
123
136
  end
124
137
  end
138
+
139
+ api_feature "Built-in acceptance test DSL" do
140
+ background "with something set" do
141
+ @answer = 42
142
+ end
143
+
144
+ scenario "verifying something is set" do
145
+ @answer.should be 42
146
+ end
147
+ end
data/spec/test_server.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'sinatra'
2
4
 
3
5
  helpers do
@@ -40,7 +42,30 @@ get '/protected' do
40
42
  end
41
43
 
42
44
  get '/xml_doc', :provides => :xml do
43
- "<root><foo attr=\"true\">Some text<foo/></foo></root>"
45
+ <<-END
46
+ <?xml version="1.0" encoding="UTF-8"?>
47
+ <root>
48
+ <foo attr=\"true\">Some text<bar>more text</bar></foo>
49
+ </root>
50
+ END
51
+ end
52
+
53
+ get '/xml_doc_with_namespaces', :provides => :xml do
54
+ <<-END
55
+ <?xml version="1.0" encoding="UTF-8"?>
56
+ <root xmlns:fake="http://www.example.org/xmlns/fake">
57
+ <fake:foo attr=\"true\">Some text<fake:bar>more text</fake:bar></fake:foo>
58
+ </root>
59
+ END
60
+ end
61
+
62
+ get '/xml_doc_with_pathological_namespaces', :provides => :xml do
63
+ <<-END
64
+ <?xml version="1.0" encoding="UTF-8"?>
65
+ <root xmlns="http://www.example.org/xmlns/fake" xmlns:fake="http://www.example.org/xmlns/fake">
66
+ <foo attr=\"true\">Some text<bar>more text</bar></foo>
67
+ </root>
68
+ END
44
69
  end
45
70
 
46
71
  get '/json_doc', :provides => :json do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
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: 2012-09-26 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack-test