Skip to content

Instantly share code, notes, and snippets.

@kevbuchanan
Last active July 27, 2016 14:53
Show Gist options
  • Save kevbuchanan/6611072 to your computer and use it in GitHub Desktop.
Save kevbuchanan/6611072 to your computer and use it in GitHub Desktop.
A basic comparison of RSpec and Jasmine tests.

RSpec vs Jasmine

A very basic intro to Jasmine tests for those familiar with RSpec

let/before

  let(:post) { Post.new("My Title", "My Content") }
  var post
  
  beforeEach(function() {
    post = new Post("My Title", "My Content")
  })

describe

  describe Post do
  
  end
  describe("Post", function() {
    // setup a post with a before block
  })

it

  it "should have a title" do
    expect(post.title).to eq("My Title")
  end
  it("should have a title", function() {
    expect(post.title).toEqual("My Title")
  })

stub

  before do
    Blog.stub(:add).and_return(true)
  end
  var blog
  
  beforeEach(function() {
    blog = new Blog()
    spyOn(blog, "add").andReturn(true)
  })

be_a

  expect(blog.posts.first).to be_a(Post)
  expect(blog.posts[0]).toEqual(jasmine.any(Post))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment