Skip to content

Commit

Permalink
Added specs for spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
polarblau committed Jun 3, 2012
1 parent 946cd1f commit 8521c0f
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<script type="text/javascript" src="jasmine/jasmine-1.2.0/jasmine-html.js"></script>

<script type="text/javascript" src="jasmine/jasmine-jquery-1.3.2/jasmine-jquery.js"></script>
<script type="text/javascript" src="helpers/jsdiff.js"></script>

<!-- vendor -->
<!-- VENDOR: ######################################### -->
<script type="text/javascript" src="../js/lib/vendor/jquery.js"></script>
Expand Down
81 changes: 81 additions & 0 deletions spec/lib/capybara/specs_spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
describe 'Capybara specs', ->

specs = null
ACTION_DATA_MOCK =
type : 'action',
name : 'clickLink',
locator: 'foobar',
scope : null
options: {}
MATCHER_DATA_MOCK =
type : 'matcher',
name : 'shouldHaveSelector',
selector: '#foo',
scope : null
options : {}
SCOPED_ACTION_DATA_MOCK =
_.extend {}, ACTION_DATA_MOCK, scope: 'form-scope'

beforeEach ->
specs = new Capybara.Specs tabURL: '/foo'

describe '#add', ->

it 'should store the added generators', ->
before = specs.generators.length
specs.add { type: 'action' }
expect(specs.generators.length).toBeGreaterThan(before)

describe '#setName', ->

it 'should change the specs name', ->
specs.setName 'foo'
expect(specs.name).toBe('foo')

describe '#generate', ->

it 'should generate basic structure', ->
expectedOutput = """
it 'SHOULDDOSOMETHING' do
visit('/foo')
end
"""
expect(specs.generate()).toEqual(expectedOutput)

describe 'actions', ->

it 'should wrap action generator output', ->
specs.add(ACTION_DATA_MOCK)
expectedOutput = """
it 'SHOULDDOSOMETHING' do
visit('/foo')
click_link('foobar')
end
"""
expect(specs.generate()).toEqual(expectedOutput)

describe 'with scope', ->

it 'should wrap the generator output', ->
specs.add(SCOPED_ACTION_DATA_MOCK)
expectedOutput = """
it 'SHOULDDOSOMETHING' do
visit('/foo')
within('form-scope') do
click_link('foobar')
end
end
"""
expect(specs.generate()).toEqual(expectedOutput)

describe 'matchers', ->

it 'should wrap matcher generator output', ->
specs.add(MATCHER_DATA_MOCK)
expectedOutput = """
it 'SHOULDDOSOMETHING' do
visit('/foo')
page.should have_selector('#foo')
end
"""
expect(specs.generate()).toEqual(expectedOutput)
74 changes: 73 additions & 1 deletion spec/lib/capybara/specs_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8521c0f

Please sign in to comment.