Created
April 4, 2011 13:12
-
-
Save eniolopes/901610 to your computer and use it in GitHub Desktop.
erro com should_receive rspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "monta 8 itens" do | |
@gerador.should_receive(:monta_conteudo_item).with(instance_of(Item)).exactly(8).times | |
@gerador.gerar_html #linha 72 | |
end | |
Output: | |
monta 8 itens (FAILED - 1) | |
Failures: | |
1) GeradorDocumento Gerando html monta 8 itens | |
Failure/Error: @gerador.gerar_html | |
TypeError: | |
can't convert nil into String | |
# ../gerador_documento.rb:18:in `+' | |
# ../gerador_documento.rb:18:in `gerar_html' | |
# ../gerador_documento.rb:17:in `each' | |
# ../gerador_documento.rb:17:in `gerar_html' | |
# ./gerador_documento_spec.rb:72 | |
it "monta 8 itens" do | |
#@gerador.should_receive(:monta_conteudo_item).with(instance_of(Item)).exactly(8).times | |
@gerador.gerar_html | |
end | |
Quando comento não da erro. | |
def gerar_html | |
html = "" | |
modelo.itens.each do |item| #linha 17 | |
html += monta_conteudo_item(item) #linha 18 | |
end | |
html | |
end | |
def monta_conteudo_item(item) | |
if comando? item.conteudo | |
"item com comando" | |
else | |
"item sem comando" | |
end | |
end | |
def comando? conteudo | |
!conteudo.index(/\[:[^\]]*\]/).nil? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment