rspec2-rails-views-matchers 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec2-rails-views-matchers (0.0.2)
4
+ rspec2-rails-views-matchers (0.0.3)
5
5
  nokogiri (~> 1.4.4)
6
6
  rspec (>= 2.0.0)
7
7
 
data/README.md CHANGED
@@ -12,23 +12,23 @@ Install
12
12
 
13
13
  add to your Gemfile(in group :test :) ):
14
14
 
15
- gem 'rspec2-rails-views-matchers'
15
+ > gem 'rspec2-rails-views-matchers'
16
16
 
17
17
  Usage
18
18
  -----
19
19
 
20
20
  some examples:
21
21
 
22
- rendered.should have_tag('form',:with => {:action => user_path, :method => 'post'}) {
23
- with_tag "input", :with => { :name => "user[email]", :type => 'email' }
24
- with_tag "input", :with => { :name => "user[password]", :type => 'password' }
25
- with_tag "input", :with => { :name => "user[password_confirmation]", :type => 'password' }
26
- with_tag "input#special_submit", :count => 1
27
- without_tag "h1", :text => 'unneeded tag'
28
- without_tag "p", :text => /content/i
29
- }
22
+ > rendered.should have_tag('form',:with => {:action => user_path, :method => 'post'}) do
23
+ > with_tag "input", :with => { :name => "user[email]", :type => 'email' }
24
+ > with_tag "input#special_submit", :count => 1
25
+ > without_tag "h1", :text => 'unneeded tag'
26
+ > without_tag "p", :text => /content/i
27
+ > end
30
28
 
31
29
  More info
32
30
  ---------
33
31
 
34
- [On RubyDoc](http://rubydoc.info/gems/rspec2-rails-views-matchers)
32
+ You can find [on RubyDoc](http://rubydoc.info/github/kucaahbe/rspec2-rails-views-matchers/master/RSpec/Matchers), take a look at {RSpec::Matchers#have\_tag have\_tag} method.
33
+
34
+ Also, please read {file:docs/CHANGELOG.md CHANGELOG}, it might be helpful.
data/Rakefile CHANGED
@@ -1,14 +1,7 @@
1
1
  require 'bundler'
2
2
  require 'rspec/core/rake_task'
3
- require 'rake/rdoctask'
4
3
  Bundler::GemHelper.install_tasks
5
4
 
6
5
  task :default => :spec
7
6
 
8
7
  RSpec::Core::RakeTask.new
9
-
10
- Rake::RDocTask.new(:rdoc) do |rd|
11
- rd.main = "README.rdoc"
12
- rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
13
- rd.options << "--all"
14
- end
data/docs/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@ unreleased(TODO)
8
8
  * add description
9
9
  * raise exception when wrong parametres specified(:count and :minimum simultaneously)
10
10
  * organize code
11
+ * add more matchers(have\_form,with\_input)?
12
+
13
+ 0.0.3
14
+ -----
15
+
16
+ * now following will work:
17
+
18
+ > rendered.should have_tag('div') do
19
+ > with_tag('p')
20
+ > end
21
+
22
+ * tags can be specified via symbol
23
+ * classes can be specified via array or string(class-names separated by spaces), so following will work:
24
+
25
+ > '<div class="one two">'.should have_tag('div', :with => { :class => ['two', 'one'] })
26
+ > '<div class="one two">'.should have_tag('div', :with => { :class => 'two one' })
11
27
 
12
28
  0.0.2
13
29
  ------
@@ -10,9 +10,18 @@ module RSpec
10
10
  attr_reader :parent_scope, :current_scope
11
11
 
12
12
  def initialize tag, options={}, &block
13
- @tag, @options, @block = tag, options, block
13
+ @tag, @options, @block = tag.to_s, options, block
14
14
 
15
15
  if attrs = @options.delete(:with)
16
+ if classes=attrs.delete(:class)
17
+ classes = case classes
18
+ when Array
19
+ classes.join('.')
20
+ when String
21
+ classes.gsub("\s",'.')
22
+ end
23
+ @tag << '.'+classes
24
+ end
16
25
  html_attrs_string=''
17
26
  attrs.each_pair { |k,v| html_attrs_string << %Q{[#{k.to_s}='#{v.to_s}']} }
18
27
  @tag << html_attrs_string
@@ -23,7 +32,8 @@ module RSpec
23
32
  @options[:maximum] ||= @options.delete(:max)
24
33
  end
25
34
 
26
- def matches?(document)
35
+ def matches? document, &block
36
+ @block = block if block
27
37
 
28
38
  case document
29
39
  when String
@@ -104,11 +114,12 @@ module RSpec
104
114
  #
105
115
  # @param [String] tag css selector for tag you want to match
106
116
  # @param [Hash] options options hash(see below)
117
+ # @option options [Hash] :with hash with other attributes, within this, key :class have special meaning, you may specify it as array of expected classes or string of classes separated by spaces, order does not matter
107
118
  # @option options [Fixnum] :count count of matched tags(DO NOT USE :count with :minimum(:min) or :maximum(:max)*)
108
119
  # @option options [Range] :count count of matched tags should be between range minimum and maximum values
109
- # @option options [Fixnum] :minimum
120
+ # @option options [Fixnum] :minimum minimum count of elements to match
110
121
  # @option options [Fixnum] :min same as :minimum
111
- # @option options [Fixnum] :maximum
122
+ # @option options [Fixnum] :maximum maximum count of elements to match
112
123
  # @option options [Fixnum] :max same as :maximum
113
124
  #
114
125
  #
@@ -116,7 +127,7 @@ module RSpec
116
127
  # rendered.should have_tag('div')
117
128
  # rendered.should have_tag('h1.header')
118
129
  # rendered.should have_tag('div#footer')
119
- # rendered.should have_tag('input#email', with => { :name => 'user[email]', :type => 'email' } )
130
+ # rendered.should have_tag('input#email', :with => { :name => 'user[email]', :type => 'email' } )
120
131
  # rendered.should have_tag('div', :count => 3) # matches exactly 3 'div' tags
121
132
  # rendered.should have_tag('div', :count => 3..7) # something like have_tag('div', :minimum => 3, :maximum => 7)
122
133
  # rendered.should have_tag('div', :minimum => 3) # matches more(or equal) than 3 'div' tags
@@ -128,6 +139,8 @@ module RSpec
128
139
  # <h1>some html document</h1>
129
140
  # </body>
130
141
  # </html>".should have_tag('body') { with_tag('h1', :text => 'some html document') }
142
+ # '<div class="one two">'.should have_tag('div', :with => { :class => ['two', 'one'] })
143
+ # '<div class="one two">'.should have_tag('div', :with => { :class => 'two one' })
131
144
  def have_tag tag,options={}, &block
132
145
  @__current_scope_for_nokogiri_matcher = NokogiriMatcher.new(tag, options, &block)
133
146
  end
data/lib/version.rb CHANGED
@@ -6,7 +6,7 @@ module RSpec#:nodoc:
6
6
  # @private
7
7
  module Matchers#:nodoc:
8
8
  # @private
9
- VERSION = "0.0.2"
9
+ VERSION = "0.0.3"
10
10
  end
11
11
  end
12
12
  end
@@ -9,7 +9,7 @@ describe 'have_tag' do
9
9
 
10
10
  before :each do
11
11
  render_html <<HTML
12
- <div>
12
+ <div class="class-one class-two">
13
13
  some content
14
14
  <div id="div">some other div</div>
15
15
  <p class="paragraph">la<strong>lala</strong></p>
@@ -23,6 +23,7 @@ HTML
23
23
 
24
24
  it "should find tags" do
25
25
  rendered.should have_tag('div')
26
+ rendered.should have_tag(:div)
26
27
  rendered.should have_tag('div#div')
27
28
  rendered.should have_tag('p.paragraph')
28
29
  rendered.should have_tag('div p strong')
@@ -30,6 +31,7 @@ HTML
30
31
 
31
32
  it "should not find tags" do
32
33
  rendered.should_not have_tag('span')
34
+ rendered.should_not have_tag(:span)
33
35
  rendered.should_not have_tag('span#id')
34
36
  rendered.should_not have_tag('span#class')
35
37
  rendered.should_not have_tag('div div span')
@@ -51,11 +53,34 @@ HTML
51
53
 
52
54
  it "should find tags" do
53
55
  rendered.should have_tag('input#search',:with => {:type => "text"})
54
- rendered.should have_tag('input',:with => {:type => "submit", :value => "Save"})
56
+ rendered.should have_tag(:input ,:with => {:type => "submit", :value => "Save"})
57
+ end
58
+
59
+ it "should find tags that have classes specified via array(or string)" do
60
+ rendered.should have_tag('div',:with => {:class => %w(class-one class-two)})
61
+ rendered.should have_tag('div',:with => {:class => 'class-two class-one'})
62
+ end
63
+
64
+ it "should not find tags that have classes specified via array" do
65
+ rendered.should_not have_tag('div',:with => {:class => %w(class-other class-two)})
66
+ end
67
+
68
+ it "should not find tags that have classes specified via array and display appropriate message" do
69
+ expect do
70
+ rendered.should have_tag('div',:with => {:class => %w(class-other class-two)})
71
+ end.should raise_spec_error(
72
+ %Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
73
+ )
74
+ expect do
75
+ rendered.should have_tag('div',:with => {:class => 'class-other class-two'})
76
+ end.should raise_spec_error(
77
+ %Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
78
+ )
55
79
  end
56
80
 
57
81
  it "should not find tags" do
58
82
  rendered.should_not have_tag('input#search',:with => {:type => "some_other_type"})
83
+ rendered.should_not have_tag(:input, :with => {:type => "some_other_type"})
59
84
  end
60
85
 
61
86
  it "should not find tags and display appropriate message" do
@@ -226,6 +251,14 @@ HTML
226
251
  }
227
252
  end
228
253
 
254
+ it "should handle do; end" do
255
+ expect do
256
+ rendered.should have_tag('ol') do
257
+ with_tag('div')
258
+ end
259
+ end.should raise_spec_error(/have at least 1 element matching "div", found 0/)
260
+ end
261
+
229
262
  it "should not find tags and display appropriate message" do
230
263
  ordered_list_regexp = @ordered_list.gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
231
264
  expect {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec2-rails-views-matchers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - kucaahbe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-23 00:00:00 +02:00
18
+ date: 2011-03-02 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency