Skip to content

Commit

Permalink
spec: use the new expect style
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Jan 22, 2014
1 parent 33c0ed0 commit 4573b4f
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 110 deletions.
38 changes: 19 additions & 19 deletions spec/dom/builder_spec.rb
Expand Up @@ -2,27 +2,27 @@

describe Browser::DOM::Builder do
it 'builds an element' do
DOM {
expect(DOM {
div
}.name.should == 'DIV'
}.name).to eq('DIV')
end

it 'builds an element with text content' do
DOM {
expect(DOM {
div "foo bar"
}.text.should == "foo bar"
}.text).to eq('foo bar')

DOM {
expect(DOM {
div {
"foo bar"
}
}.text.should == "foo bar"
}.text).to eq('foo bar')
end

it 'builds an element with attributes' do
DOM {
expect(DOM {
div class: :wut
}.class_name.should == :wut
}.class_name).to eq(:wut)
end

it 'builds deeper trees' do
Expand All @@ -34,15 +34,15 @@
}
}

res.name.should == 'DIV'
res.child.name.should == 'SPAN'
res.child.text.should == 'wut'
expect(res.name).to eq('DIV')
expect(res.child.name).to eq('SPAN')
expect(res.child.text).to eq('wut')
end

it 'sets classes with methods' do
DOM {
expect(DOM {
div.nice.element
}.class_names.should == %w[nice element]
}.class_names).to eq(%w[nice element])
end

it 'nests when setting classes' do
Expand All @@ -52,18 +52,18 @@
}
}

res.name.should == 'DIV'
res.class_names.should == %w[nice element]
res.child.name.should == 'SPAN'
res.child.class_names.should == %w[nicer]
expect(res.name).to eq('DIV')
expect(res.class_names).to eq(%w[nice element])
expect(res.child.name).to eq('SPAN')
expect(res.child.class_names).to eq(%w[nicer])
end

it 'joins class name properly' do
res = DOM {
i.icon[:legal]
}

res.name.should == 'I'
res.class_names.should == %w[icon-legal]
expect(res.name).to eq('I')
expect(res.class_names).to eq(%w[icon-legal])
end
end
12 changes: 6 additions & 6 deletions spec/dom/document_spec.rb
Expand Up @@ -3,15 +3,15 @@
describe Browser::DOM::Document do
describe '#title' do
it 'should get the document title' do
$document.title.should be_kind_of(String)
expect($document.title).to be_a(String)
end
end

describe '#title=' do
it 'should set the document title' do
old = $document.title
$document.title = 'lol'
$document.title.should == 'lol'
expect($document.title).to eq('lol')
$document.title = old
end
end
Expand All @@ -22,19 +22,19 @@
HTML

it "should get element by id" do
$document["lol"].should == `#{$document.to_n}.getElementById('lol')`
expect($document["lol"]).to eq(`#{$document.to_n}.getElementById('lol')`)
end

it "should get element by css" do
$document["lol"].should == `#{$document.to_n}.getElementById('lol')`
expect($document["lol"]).to eq(`#{$document.to_n}.getElementById('lol')`)
end

it "should get element by xpath" do
$document["//*[@id='lol']"].should == `#{$document.to_n}.getElementById('lol')`
expect($document["//*[@id='lol']"]).to eq(`#{$document.to_n}.getElementById('lol')`)
end

it "should return nil if it can't find anything" do
$document["doo-dah"].should be_nil
expect($document["doo-dah"]).to be_nil
end
end
end
10 changes: 5 additions & 5 deletions spec/dom/element_spec.rb
Expand Up @@ -7,7 +7,7 @@
HTML

it 'gets the proper id' do
$document["lol"].id.should == 'lol'
expect($document["lol"].id).to eq('lol')
end
end

Expand All @@ -20,11 +20,11 @@
HTML

it 'gives an empty array when no class is set' do
$document["class-names-2"].class_names.should == []
expect($document["class-names-2"].class_names).to eq([])
end

it 'gives an array of class names' do
$document["class-names-1"].class_names.should == %w[a b c]
expect($document["class-names-1"].class_names).to eq(%w[a b c])
end
end

Expand All @@ -36,11 +36,11 @@
HTML

it 'matches on class and id' do
$document[:matches].matches?('#matches.not.me').should be_truthy
expect($document[:matches].matches?('#matches.not.me')).to be_truthy
end

it 'matches on class and name' do
$document[:matches].first_element_child.matches?('span.yes').should be_truthy
expect($document[:matches].first_element_child.matches?('span.yes')).to be_truthy
end
end
end
32 changes: 16 additions & 16 deletions spec/dom/event_spec.rb
Expand Up @@ -16,13 +16,13 @@
count += 1
end

count.should == 0
expect(count).to eq(0)
elem.trigger :click
count.should == 1
expect(count).to eq(1)
elem.trigger :click
count.should == 2
expect(count).to eq(2)
elem.trigger 'mouse:down'
count.should == 2
expect(count).to eq(2)
end

it "listens for custom events" do
Expand All @@ -33,19 +33,19 @@
count += 1
end

count.should == 0
expect(count).to eq(0)
elem.trigger :huehue
count.should == 1
expect(count).to eq(1)
elem.trigger :huehue
count.should == 2
expect(count).to eq(2)
end

async "passes an event to the handler" do
elem = $document["event-spec"]

elem.on :click do |event|
run_async {
event.should be_kind_of Browser::DOM::Event
expect(event).to be_a(Browser::DOM::Event)
}
end

Expand All @@ -57,9 +57,9 @@

elem.on :bazinga do |event, foo, bar, baz|
run_async {
foo.should == 1
bar.should == 2
baz.should == 3
expect(foo).to eq(1)
expect(bar).to eq(2)
expect(baz).to eq(3)
}
end

Expand All @@ -71,7 +71,7 @@

elem.on :bazinga, 'span.nami' do
run_async {
true.should be_truthy
expect(true).to be_truthy
}
end

Expand All @@ -97,11 +97,11 @@
end

elem.trigger :click
count.should == 2
expect(count).to eq(2)

elem.off :click
elem.trigger :click
count.should == 2
expect(count).to eq(2)
end

it "removes only the passed handler" do
Expand All @@ -117,11 +117,11 @@
end

elem.trigger :click
count.should == 2
expect(count).to eq(2)

cb.off
elem.trigger :click
count.should == 3
expect(count).to eq(3)
end
end
end
4 changes: 2 additions & 2 deletions spec/dom/mutation_observer_spec.rb
Expand Up @@ -10,7 +10,7 @@
async 'notifies additions' do
obs = Browser::DOM::MutationObserver.new {|mutations|
run_async {
mutations.first.added.first.name.should == 'DIV'
expect(mutations.first.added.first.name).to eq('DIV')
}

obs.disconnect
Expand All @@ -24,7 +24,7 @@
async 'notifies removals' do
obs = Browser::DOM::MutationObserver.new {|mutations|
run_async {
mutations.first.removed.first.name.should == 'SPAN'
expect(mutations.first.removed.first.name).to eq('SPAN')
}

obs.disconnect
Expand Down

0 comments on commit 4573b4f

Please sign in to comment.