few components with rspec3 syntax

This commit is contained in:
Luciano Sousa
2015-01-09 13:34:37 -03:00
parent c96220ca76
commit 0fd98b56d8
97 changed files with 1620 additions and 1618 deletions

View File

@ -33,45 +33,45 @@ describe Email::Receiver do
end
it "can parse the html section" do
test_parse_body(fixture_file("emails/html_only.eml")).should == "The EC2 instance - I've seen that there tends to be odd and " +
"unrecommended settings on the Bitnami installs that I've checked out."
expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " +
"unrecommended settings on the Bitnami installs that I've checked out.")
end
it "supports a Dutch reply" do
test_parse_body(fixture_file("emails/dutch.eml")).should == "Dit is een antwoord in het Nederlands."
expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.")
end
it "supports a Hebrew reply" do
I18n.expects(:t).with('user_notifications.previous_discussion').returns('כלטוב')
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
test_parse_body(fixture_file("emails/hebrew.eml")).should == "שלום"
expect(test_parse_body(fixture_file("emails/hebrew.eml"))).to eq("שלום")
end
it "supports a BIG5-encoded reply" do
I18n.expects(:t).with('user_notifications.previous_discussion').returns('媽!我上電視了!')
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
test_parse_body(fixture_file("emails/big5.eml")).should == "媽!我上電視了!"
expect(test_parse_body(fixture_file("emails/big5.eml"))).to eq("媽!我上電視了!")
end
it "removes 'via' lines if they match the site title" do
SiteSetting.title = "Discourse"
test_parse_body(fixture_file("emails/via_line.eml")).should == "Hello this email has content!"
expect(test_parse_body(fixture_file("emails/via_line.eml"))).to eq("Hello this email has content!")
end
it "removes an 'on date wrote' quoting line" do
test_parse_body(fixture_file("emails/on_wrote.eml")).should == "Sure, all you need to do is frobnicate the foobar and you'll be all set!"
expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!")
end
it "removes the 'Previous Discussion' marker" do
test_parse_body(fixture_file("emails/previous.eml")).should == "This will not include the previous discussion that is present in this email."
expect(test_parse_body(fixture_file("emails/previous.eml"))).to eq("This will not include the previous discussion that is present in this email.")
end
it "handles multiple paragraphs" do
test_parse_body(fixture_file("emails/paragraphs.eml")).
should == (
expect(test_parse_body(fixture_file("emails/paragraphs.eml"))).
to eq(
"Is there any reason the *old* candy can't be be kept in silos while the new candy
is imported into *new* silos?
@ -83,8 +83,8 @@ Thanks for listening."
end
it "handles multiple paragraphs when parsing html" do
test_parse_body(fixture_file("emails/html_paragraphs.eml")).
should == (
expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))).
to eq(
"Awesome!
Pleasure to have you here!
@ -94,8 +94,8 @@ Pleasure to have you here!
end
it "handles newlines" do
test_parse_body(fixture_file("emails/newlines.eml")).
should == (
expect(test_parse_body(fixture_file("emails/newlines.eml"))).
to eq(
"This is my reply.
It is my best reply.
It will also be my *only* reply."
@ -103,8 +103,8 @@ It will also be my *only* reply."
end
it "handles inline reply" do
test_parse_body(fixture_file("emails/inline_reply.eml")).
should == (
expect(test_parse_body(fixture_file("emails/inline_reply.eml"))).
to eq(
"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ <info@unconfigured.discourse.org> wrote:
> techAPJ <https://meta.discourse.org/users/techapj>
@ -150,16 +150,16 @@ the lazy dog. The quick brown fox jumps over the lazy dog."
end
it "should not include previous replies" do
test_parse_body(fixture_file("emails/previous_replies.eml")).should_not match /Previous Replies/
expect(test_parse_body(fixture_file("emails/previous_replies.eml"))).not_to match /Previous Replies/
end
it "strips iPhone signature" do
test_parse_body(fixture_file("emails/iphone_signature.eml")).should_not match /Sent from my iPhone/
expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match /Sent from my iPhone/
end
it "properly renders email reply from gmail web client" do
test_parse_body(fixture_file("emails/gmail_web.eml")).
should == (
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
to eq(
"### This is a reply from standard GMail in Google Chrome.
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
@ -175,8 +175,8 @@ Here's a link http://example.com"
end
it "properly renders email reply from iOS default mail client" do
test_parse_body(fixture_file("emails/ios_default.eml")).
should == (
expect(test_parse_body(fixture_file("emails/ios_default.eml"))).
to eq(
"### this is a reply from iOS default mail
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
@ -188,8 +188,8 @@ Here's a link http://example.com"
end
it "properly renders email reply from Android 5 gmail client" do
test_parse_body(fixture_file("emails/android_gmail.eml")).
should == (
expect(test_parse_body(fixture_file("emails/android_gmail.eml"))).
to eq(
"### this is a reply from Android 5 gmail
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
@ -204,8 +204,8 @@ This is a link to http://example.com"
end
it "properly renders email reply from Windows 8.1 Metro default mail client" do
test_parse_body(fixture_file("emails/windows_8_metro.eml")).
should == (
expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))).
to eq(
"### reply from default mail client in Windows 8.1 Metro
@ -220,12 +220,12 @@ This is a link http://example.com"
end
it "properly renders email reply from MS Outlook client" do
test_parse_body(fixture_file("emails/outlook.eml")).should == "Microsoft Outlook 2010"
expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010")
end
it "converts back to UTF-8 at the end" do
result = test_parse_body(fixture_file("emails/big5.eml"))
result.encoding.should == Encoding::UTF_8
expect(result.encoding).to eq(Encoding::UTF_8)
# should not throw
TextCleaner.normalize_whitespaces(
@ -269,11 +269,11 @@ This is a link http://example.com"
receiver.process
topic.posts.count.should == (start_count + 1)
expect(topic.posts.count).to eq(start_count + 1)
created_post = topic.posts.last
created_post.via_email.should == true
created_post.raw_email.should == fixture_file("emails/valid_reply.eml")
created_post.cooked.strip.should == fixture_file("emails/valid_reply.cooked").strip
expect(created_post.via_email).to eq(true)
expect(created_post.raw_email).to eq(fixture_file("emails/valid_reply.eml"))
expect(created_post.cooked.strip).to eq(fixture_file("emails/valid_reply.cooked").strip)
end
end
@ -286,9 +286,9 @@ This is a link http://example.com"
receiver.process
topic.posts.count.should == (start_count + 1)
topic.posts.last.cooked.strip.should == fixture_file("emails/paragraphs.cooked").strip
topic.posts.last.cooked.should_not match /<br/
expect(topic.posts.count).to eq(start_count + 1)
expect(topic.posts.last.cooked.strip).to eq(fixture_file("emails/paragraphs.cooked").strip)
expect(topic.posts.last.cooked).not_to match /<br/
end
end
@ -308,9 +308,9 @@ This is a link http://example.com"
receiver.process
topic.posts.count.should == (start_count + 1)
topic.posts.last.cooked.should match /<img src=['"](\/uploads\/default\/\d+\/\w{16}\.png)['"] width=['"]289['"] height=['"]126['"]>/
Upload.find_by(sha1: upload_sha).should_not == nil
expect(topic.posts.count).to eq(start_count + 1)
expect(topic.posts.last.cooked).to match /<img src=['"](\/uploads\/default\/\d+\/\w{16}\.png)['"] width=['"]289['"] height=['"]126['"]>/
expect(Upload.find_by(sha1: upload_sha)).not_to eq(nil)
end
end
@ -448,7 +448,7 @@ This is a link http://example.com"
expect { receiver.process }.to raise_error(Email::Receiver::InvalidPost)
Topic.count.should == before_topic_count
expect(Topic.count).to eq(before_topic_count)
end
end
@ -549,7 +549,7 @@ greatest show ever created. Everyone should watch it.
user.save
process_email(from: user.email, to: to)
user.posts.count.should == 1
expect(user.posts.count).to eq(1)
# email too short
message = nil
@ -559,7 +559,7 @@ greatest show ever created. Everyone should watch it.
message = e.message
end
e.message.should include("too short")
expect(e.message).to include("too short")
end
end
@ -581,7 +581,7 @@ greatest show ever created. Everyone should watch it.
process_email(from: "test@test.com", to: "bob@bob.com")
# This is the current implementation but it is wrong, it should register an account
Discourse.system_user.posts.order("id desc").limit(1).pluck(:raw).first.should include("Hey folks")
expect(Discourse.system_user.posts.order("id desc").limit(1).pluck(:raw).first).to include("Hey folks")
end