Permalink
Browse files

Added specs for matcher generator.

  • Loading branch information...
1 parent 18e2752 commit 87d64b9e2ed9cecb586aa34793ab9e09075ff013 @polarblau committed Jun 1, 2012
@@ -14,7 +14,7 @@ class Capybara.Generators.Matcher
["within_form('#{locator}') do", "end"]
- constructor: (data) ->
+ constructor: (data = {}) ->
@data = data
isScoped: ->

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,48 @@
+describe 'Capybara matcher generator', ->
+
+ describe '#isScoped', ->
+
+ it 'should return true if scope provided', ->
+ generator = new Capybara.Generators.Matcher(scope: '#foo')
+ expect(generator.isScoped()).toBeTruthy()
+
+ it 'should return false if no scope provided', ->
+ generator = new Capybara.Generators.Matcher
+ expect(generator.isScoped()).toBeFalsy()
+
+ describe 'templates', ->
+ generator = null
+ allOptions =
+ scope: '#foo'
+ selector: '.foo.bar'
+ options:
+ content: 'Foo bar'
+
+ describe '#scopeTemplate', ->
+
+ beforeEach ->
+ generator = new Capybara.Generators.Matcher(allOptions)
+
+ it 'should return an array', ->
+ expect(typeof generator.scopeToPartials()).toBe('object')
+
+ it 'should match a tempate', ->
+ out = generator.scopeToPartials()
+ expect(out.length).toEqual(2)
+ expect(out[0]).toBe("within_form('#foo') do")
+ expect(out[1]).toBe('end')
+
+ describe '#toString', ->
+
+ expectations =
+ 'shouldHaveSelector': "page.should have_selector('.foo.bar')"
+ 'shouldHaveContent' : "page.should have_content('Foo bar')"
+
+ for method, template of expectations
+
+ it "should return correct template for #{method}", ->
+ options = _.extend(allOptions, name: method)
+ generator = new Capybara.Generators.Matcher(options)
+
+ expect(generator.toString()).toBe(template)
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 87d64b9

Please sign in to comment.