Coder Social home page Coder Social logo

jasmine-fixture-builder's Introduction

Build Status Code Climate Test Coverage

Jasmine Fixture Builder

Jasmine Fixture Builder (or "JazzFix" for short) allows you to generate fixtures for your jasmine specs based on the DOM your application renders. Don't let your jasmine fixtures get stale and lie to you - use JazzFix to keep your application's DOM and jasmine specs in sync!

Dependencies

JazzFix works alongside the use of the following:

  • rails
  • jquery
  • rspec-rails
  • jasmine
  • jasmine-jquery

JazzFix leverages the fixture loading ability of jasmine-jquery along with the clean DOM rendering that rspec-rails view specs provide. JazzFix owes a debt of gratitude to the work and subsequent experience report from JB Steadman.

Installation

Add the following gems to application's gem file, grouped to development/test:

  • jasmine
  • jasmine-jquery-rails
  • jasmine_fixture_builder

(rspec-rails is a dependency of jasmine_fixture_builder, so there is no need to explicitly add it to your gem file as a dependency)

Run the following:

  • bundle install
  • rails generate rspec:install
  • rails generate jasmine:install

Add assets/jasmine-jquery.js underneath the src_files item in your jasmine.yml, which should live in the spec/javascripts/support directory.

Usage

###Create a fixture with RSpec:

Create a view spec for a particular view you want to create a fixture from. Render the view, then save the rendered html to a fixture with the provided save_fixture method:

describe 'widgets/index' do
	it 'creates fixture' do
		render
		save_fixture(rendered, 'widgets_index.html')
	end
end

save_fixture takes 2 arguments: the markup as its first, the name to ascribe the fixture to as its second.

This saves the markup from the view into a file living at spec/javascripts/fixtures/widgets_index.html.

###Use that fixture in your Jasmine test:

Utilize the loadFixture method from jasmine-jquery to load up the fixture for use in your test. loadFixture inserts the markup from your fixture into a container <div id='jasmine-fixtures'></div>.

describe('widgets/index', function() {
	it('tests javascript action', function() {
		//load the fixture
		loadFixture('widgets_index.html');

		// test some javascript action
		$('#jasmine-fixtures .some-button').click();

		// make an assertion
		$('#jasmine-fixtures .some-container').toHaveText('text');
	});
});

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/jasmine_fixture_builder/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

jasmine-fixture-builder's People

Contributors

jleo3 avatar surzhko avatar verdammelt avatar jjiadev avatar jesusmarlima avatar boovius avatar

Stargazers

Luka Huang avatar Collin Meyers avatar Corey Leveen avatar  avatar Ben Liscio avatar

Watchers

 avatar Joshua Hawkins avatar  avatar Paul Ort avatar James Cloos avatar Steve Brudz avatar James Duffy avatar Keith avatar Ben Liscio avatar  avatar  avatar  avatar MfP avatar Michael Deertz avatar

jasmine-fixture-builder's Issues

Remove directory creation from RSpec::Matcher

Remove

    Dir.mkdir(fixture_path) unless File.exists?(fixture_path)

from lib/jasmine_fixture_builder.rb.

Also, move the functionality out of lib/jasmine_fixture_builder.rb and into a new file, lib/jasmine_fxture_builder/rspec_matchers.rb

Format rendered HTML output

All HTML is currently persisted left-justified to each fixture file. Format so that proper indentation is observed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.