It’s a humbling and amazing thing to work on Windows, which is used by over 1.5 billion people in every country of the world. From kids playing with computers for the first time, to writers and journalists, to engineers, to gamers, to CEOs, at some point Windows has empowered all of us.
In the Windows team, we’re proud of this – but we also know that the world today is very different from the one in which Windows grew up. Today, devices outnumber people. Connectivity is like oxygen. The tension between the desire for agility versus stability poses a huge challenge for IT Pros. Experiences – no matter what device you’re on – just need to work. The only thing that hasn’t really changed is the situation for developers – still too much to do, and not enough time.
Faster, smaller, greener computers, capable of processing information up to 1,000 times faster than currently available models, could be made possible by replacing silicon with materials that can switch back and forth between different electrical states.
Straight to the point.
open up terminal and create a new Rails project, simple_test:
$ rails new simple_test --skip-test-unit
$ cd simple_test
--skip-test-unit, tells Rails not to generate a test directory
associated with Test::Unit framework. this is because we want to use
another testing framework named RSpec to write our tests.
then we need to include RSpec Gem in 'Gemfile' in your project root directory
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
rspec-rails in a development environment so that we have access to
RSpec-specific generators, and it includes it in test mode in order to
run the tests. We don’t have to install RSpec itself because it is a
dependency of rspec-rails and will thus be installed automatically. We
also include the Capybara gem, which allows us to simulate a user’s
interaction with the sample application using a natural English-like
syntax, together with Selenium, one of Capybara’s dependencies.
$ bundle install
it might be
better to update the gems with bundle update to make sure the versions
match, and then run bundle install to make sure the Gemfile.lock file is
Next, we need to configure Rails to use RSpec in place of Test::Unit.
$rails generate rspec:install
you should see:
if you're using sublimeText, you can open the entire project by navigating to your project directory and then
$ subl .
or any other editor.
ok, now we set to
start developing. since we're following MVC pattern here, I jut give an
short overview about that. model is your data access layer. view is
your presentation layer, and controller is your business logic layer.
business layer i.e. controllers, are between those 2 other layers.
it means, if some
data needs to be shown by presentation layer, i.e. views, it can't
access the model (data access layer, or database side) by itself. it
needs to go through the business layer i.e. controllers.
now if you opened
the entire project in your editor, and then go into 'app' folder in
project root directory you'll see folders related to these layers,
models, views, controller. there are some convention here which makes
the development easier, which you can search it for yourself.
now lets make a controller:
rails generate controller StaticPages home help --no-test-framework
option suppresses the generation of the default RSpec tests, which we
won’t be using. Instead, we’ll create the tests by hand. this will
generates a controller, StaticPages, with 2 action methods : home and
help, which both represent 2 pages(look into app/view/static_pages).
now, since i just want to show how TDD works, i don't go into details on
how writing tests for the existing code. instead suppose i want to add
another page, About.
development, we first write a failing test, represented in many testing
tools by the color red. We then implement code to get the test to pass,
represented by the color green. Finally, if necessary, we refactor the
code, changing its form (by eliminating duplication, for example)
without changing its function. This cycle is known as “Red, Green,
because here, i'll do integration testing we need to run following command:
This creates the
static_pages_spec.rb in the spec/requests directory. As with most
generated code to use the Capybara you need to add the following line
RSpec.configure do |config|
we have a controller, static_pages_controller, it has 2 action methods,
home, help and we want to add another one, about. we have RSpec
installed, and we execute the rails generate integration_test
static_pages, which generated spec/requests/static_pages_spec.rb for us.
we put our test inside that file.
We’ll start the testing cycle by writing a failing test for the About page.
describe "Static pages" do
describe "About page" do
it "should have the content 'About Us'" do
expect(page).to have_content('About Us')
says that we are missing a “template”, i.e., a view:
Missing template static_pages/about
To solve this
issue, we add the about view. This involves creating a new file called
about.html.erb in the app/views/static_pages directory with following
<h1>About Us </h1>
Running the test again
The test uses the *have_title* method, which checks for an HTML title with the given content. In other words, the code
expect(page).to have_title("About Us")
to pass the test
you just need to change the title of about page to "Abut Us" in its
relevant view file in app/views folder, which is easy
some side notes:
these tests are
technically integration tests, however writing unit tests are similar.
you just test the data based on your model, for example for invalid
data, or password length. etc.
I tried to be more detailed and descriptive, sorry if that's so long.all the steps have been tested on Kubuntu 14.04this was adopted mostly from http://www.railstutorial.org/if you see any errors, leave a comment please. better version can be found here <a href="http://krakenaround.blogspot.com.au/2014/08/simple-step-by-step-testing-in-ruby-on.html"> Test on Ruby On Rails </a>
Much of the water on Earth and elsewhere in the solar system likely predates the birth of the sun, a new study reports.The finding suggests that water is commonly incorporated into newly forming planets throughout the Milky Way galaxy and beyond, researchers said — good news for anyone hoping that Earth isn't the only world to host life.
Apple Inc. (AAPL) sold a record of more than 10 million iPhones the first weekend two new versions hit stores, helping Chief Executive Officer Tim Cook in a push to narrow Samsung Electronics Co.'s lead in bigger-screen smartphones.
Nothing gets DBAs more riled up than a developer infatuated with an Object-Relational Mapper. ORMs work great at mapping from relational to objects, but can be a crutch. If you want to make your DBA (and your users happy), you’ll want to use your ORM intelligently. In this session, we’ll look at application patterns, ORM features and more to discover the right way of using your ORM. We’ll also look at when to ditch your heavyweight ORM and reach for a lighter one. Finally, we’ll cover why abstracting your ORM is evil and alternatives that give us more flexibility and maintainability in the long run.
Apple’s iOS 8, the latest version of the operating system for iPhone, iPad, and iPod, is now available. It’s pretty darn slick, and it’s what everyone who orders a new iPhone 6 will get when those devices start arriving on Friday. But the upgrade is also available for existing Apple devices.